blob: cf9f8502c722708e2c91729b9ba04e9e544f203c [file] [log] [blame]
Chris Lattnercc67ec12006-11-09 06:54:47 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
Chris Lattner7cee11f2006-11-03 06:42:29 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-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 Lattner7cee11f2006-11-03 06:42:29 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattnercc67ec12006-11-09 06:54:47 +000010// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
Chris Lattner7cee11f2006-11-03 06:42:29 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattnercc67ec12006-11-09 06:54:47 +000015#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
Chris Lattner7cee11f2006-11-03 06:42:29 +000017
Chris Lattnerc5c95b52008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidised983422008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Douglas Gregor5251f1b2008-10-21 16:13:35 +000020#include "SemaOverload.h"
Douglas Gregor34074322009-01-14 22:20:51 +000021#include "clang/AST/DeclBase.h"
Chris Lattner7cee11f2006-11-03 06:42:29 +000022#include "clang/Parse/Action.h"
Chris Lattnerbc495d72008-11-22 08:28:49 +000023#include "clang/Basic/Diagnostic.h"
Anders Carlsson51873c22007-07-22 07:07:56 +000024#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian458f7112007-10-05 18:00:57 +000025#include "llvm/ADT/DenseSet.h"
Chris Lattneree2d8412007-10-07 01:13:46 +000026#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidised983422008-07-01 10:37:29 +000027#include "llvm/ADT/OwningPtr.h"
Douglas Gregor39c16d42008-10-24 04:54:22 +000028#include <vector>
Chris Lattner7cee11f2006-11-03 06:42:29 +000029
Chris Lattnerfc1c44a2007-08-23 05:46:52 +000030namespace llvm {
31 class APSInt;
32}
33
Chris Lattner7cee11f2006-11-03 06:42:29 +000034namespace clang {
Chris Lattnercb6a3822006-11-10 06:20:45 +000035 class ASTContext;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000036 class ASTConsumer;
Chris Lattner7cee11f2006-11-03 06:42:29 +000037 class Preprocessor;
38 class Decl;
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000039 class DeclContext;
Daniel Dunbar34fb6722008-08-11 03:27:53 +000040 class DeclSpec;
Steve Naroff257520b2008-04-01 23:04:06 +000041 class NamedDecl;
Steve Naroff9324db12007-09-13 18:10:37 +000042 class ScopedDecl;
Sebastian Redlc675bab2008-12-13 16:23:55 +000043 class Stmt;
Steve Naroff78403362007-04-02 22:55:05 +000044 class Expr;
Steve Narofff33527a2007-09-02 15:34:30 +000045 class InitListExpr;
Chris Lattner08464942007-12-28 05:29:59 +000046 class CallExpr;
Douglas Gregorc7acfdf2009-01-06 05:10:23 +000047 class DeclRefExpr;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000048 class VarDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000049 class ParmVarDecl;
Chris Lattner01564d92007-01-27 19:27:06 +000050 class TypedefDecl;
51 class FunctionDecl;
Steve Naroffe5aa9be2007-04-05 22:36:20 +000052 class QualType;
Chris Lattner9cf21c52007-09-04 02:45:27 +000053 struct LangOptions;
Chris Lattner146762e2007-07-20 16:59:19 +000054 class Token;
Steve Naroff35d85152007-05-07 00:24:15 +000055 class IntegerLiteral;
Steve Naroffaf2a0222008-01-22 00:55:40 +000056 class StringLiteral;
Steve Naroff8eeeb132007-05-08 21:09:37 +000057 class ArrayType;
Chris Lattnere2473062007-05-28 06:28:18 +000058 class LabelStmt;
Anders Carlsson51873c22007-07-22 07:07:56 +000059 class SwitchStmt;
Nate Begemance4d7fc2008-04-18 23:10:10 +000060 class ExtVectorType;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000061 class TypedefDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000062 class ObjCInterfaceDecl;
Steve Naroff257520b2008-04-01 23:04:06 +000063 class ObjCCompatibleAliasDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000064 class ObjCProtocolDecl;
65 class ObjCImplementationDecl;
66 class ObjCCategoryImplDecl;
67 class ObjCCategoryDecl;
68 class ObjCIvarDecl;
69 class ObjCMethodDecl;
Fariborz Jahanian7cf18862008-05-01 00:03:38 +000070 class ObjCPropertyDecl;
Steve Naroff35c62ae2009-01-08 17:28:14 +000071 class ObjCContainerDecl;
Steve Naroffc540d662008-09-03 18:15:37 +000072 struct BlockSemaInfo;
Douglas Gregor39c16d42008-10-24 04:54:22 +000073 class BasePaths;
Douglas Gregor960b5bc2009-01-15 00:26:24 +000074 class MemberLookupCriteria;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000075
Daniel Dunbar54603742008-10-14 05:35:18 +000076/// PragmaPackStack - Simple class to wrap the stack used by #pragma
77/// pack.
78class PragmaPackStack {
Daniel Dunbaraf7efa62008-11-19 10:32:38 +000079 typedef std::vector< std::pair<unsigned, IdentifierInfo*> > stack_ty;
Daniel Dunbar54603742008-10-14 05:35:18 +000080
81 /// Alignment - The current user specified alignment.
82 unsigned Alignment;
83
Daniel Dunbaraf7efa62008-11-19 10:32:38 +000084 /// Stack - Entries in the #pragma pack stack, consisting of saved
85 /// alignments and optional names.
Daniel Dunbar54603742008-10-14 05:35:18 +000086 stack_ty Stack;
87
88public:
89 PragmaPackStack(unsigned A) : Alignment(A) {}
90
91 void setAlignment(unsigned A) { Alignment = A; }
92 unsigned getAlignment() { return Alignment; }
93
94 /// push - Push the current alignment onto the stack, optionally
Daniel Dunbaraf7efa62008-11-19 10:32:38 +000095 /// using the given \arg Name for the record, if non-zero.
Daniel Dunbar54603742008-10-14 05:35:18 +000096 void push(IdentifierInfo *Name) {
Daniel Dunbaraf7efa62008-11-19 10:32:38 +000097 Stack.push_back(std::make_pair(Alignment, Name));
Daniel Dunbar54603742008-10-14 05:35:18 +000098 }
99
100 /// pop - Pop a record from the stack and restore the current
101 /// alignment to the previous value. If \arg Name is non-zero then
102 /// the first such named record is popped, otherwise the top record
103 /// is popped. Returns true if the pop succeeded.
104 bool pop(IdentifierInfo *Name);
105};
106
Chris Lattnercc67ec12006-11-09 06:54:47 +0000107/// Sema - This implements semantic analysis and AST building for C.
108class Sema : public Action {
Chris Lattnera663a0a2008-06-29 00:28:59 +0000109public:
Steve Naroff38d31b42007-02-28 01:22:02 +0000110 Preprocessor &PP;
Chris Lattnercb6a3822006-11-10 06:20:45 +0000111 ASTContext &Context;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +0000112 ASTConsumer &Consumer;
Chris Lattnerbc495d72008-11-22 08:28:49 +0000113 Diagnostic &Diags;
114 SourceManager &SourceMgr;
Steve Naroffe3d1ab22007-11-12 13:56:41 +0000115
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +0000116 /// CurContext - This is the current declaration context of parsing.
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000117 DeclContext *CurContext;
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000118
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +0000119 /// PreDeclaratorDC - Keeps the declaration context before switching to the
120 /// context of a declarator's nested-name-specifier.
121 DeclContext *PreDeclaratorDC;
122
Steve Naroffc540d662008-09-03 18:15:37 +0000123 /// CurBlock - If inside of a block definition, this contains a pointer to
124 /// the active block object that represents it.
125 BlockSemaInfo *CurBlock;
126
Daniel Dunbar54603742008-10-14 05:35:18 +0000127 /// PackContext - Manages the stack for #pragma pack. An alignment
128 /// of 0 indicates default alignment.
129 PragmaPackStack PackContext;
130
Chris Lattnere2473062007-05-28 06:28:18 +0000131 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
132 /// it (which acts like the label decl in some ways). Forward referenced
133 /// labels have a LabelStmt created for them with a null location & SubStmt.
Chris Lattner23b7eb62007-06-15 23:05:46 +0000134 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
Anders Carlsson51873c22007-07-22 07:07:56 +0000135
136 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffddf5a1d2007-07-29 16:33:31 +0000137
Nate Begemance4d7fc2008-04-18 23:10:10 +0000138 /// ExtVectorDecls - This is a list all the extended vector types. This allows
139 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffddf5a1d2007-07-29 16:33:31 +0000140 /// This is only necessary for issuing pretty diagnostics.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000141 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000142
Steve Naroff8edb5732008-09-28 14:55:53 +0000143 /// ObjCImplementations - Keep track of all class @implementations
144 /// so we can emit errors on duplicates.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000145 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattneree2d8412007-10-07 01:13:46 +0000146
Steve Naroff8edb5732008-09-28 14:55:53 +0000147 /// ObjCCategoryImpls - Maintain a list of category implementations so
148 /// we can check for duplicates and find local method declarations.
149 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
150
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000151 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian06f84f52007-10-09 18:03:53 +0000152 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner516ca702007-10-09 18:18:24 +0000153 /// find the declarations when needed.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000154 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff77892752008-04-02 18:30:49 +0000155
156 /// ObjCInterfaceDecls - Keep track of all class declarations declared
157 /// with @interface, so that we can emit errors on duplicates and
158 /// find the declarations when needed.
159 typedef llvm::DenseMap<const IdentifierInfo*,
160 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
161 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
162
Steve Naroff257520b2008-04-01 23:04:06 +0000163 /// ObjCAliasDecls - Keep track of all class declarations declared
164 /// with @compatibility_alias, so that we can emit errors on duplicates and
165 /// find the declarations when needed. This construct is ancient and will
166 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroff9b94b172008-04-02 00:39:51 +0000167 typedef llvm::DenseMap<const IdentifierInfo*,
168 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroff257520b2008-04-01 23:04:06 +0000169 ObjCAliasTy ObjCAliasDecls;
Steve Naroff77892752008-04-02 18:30:49 +0000170
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000171 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
172 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
173
Chris Lattnerc5c95b52008-04-11 07:00:53 +0000174 IdentifierResolver IdResolver;
175
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000176 // Enum values used by KnownFunctionIDs (see below).
177 enum {
Ted Kremenek34f664d2008-06-16 18:00:42 +0000178 id_NSLog,
Daniel Dunbardd9b2d12008-10-02 18:44:07 +0000179 id_asprintf,
180 id_fprintf,
181 id_printf,
182 id_snprintf,
183 id_snprintf_chk,
184 id_sprintf,
185 id_sprintf_chk,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000186 id_vasprintf,
Daniel Dunbardd9b2d12008-10-02 18:44:07 +0000187 id_vfprintf,
188 id_vsnprintf,
189 id_vsnprintf_chk,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000190 id_vsprintf,
Daniel Dunbardd9b2d12008-10-02 18:44:07 +0000191 id_vsprintf_chk,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000192 id_vprintf,
193 id_num_known_functions
194 };
195
196 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
197 /// of known functions used by the semantic analysis to do various
198 /// kinds of checking (e.g. checking format string errors in printf calls).
199 /// This list is populated upon the creation of a Sema object.
Chris Lattner2cc35ae2008-08-23 02:00:52 +0000200 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar12c9ddc2008-08-14 22:04:54 +0000201
Steve Naroff93eb5f12007-10-10 17:32:04 +0000202 /// Translation Unit Scope - useful to Objective-C actions that need
203 /// to lookup file scope declarations in the "ordinary" C decl namespace.
204 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffc62adb62007-10-09 22:01:59 +0000205 Scope *TUScope;
Sebastian Redlc4704762008-11-11 11:37:55 +0000206
207 /// The C++ "std" namespace, where the standard library resides. Cached here
208 /// by GetStdNamespace
209 NamespaceDecl *StdNamespace;
Sebastian Redlfaf68082008-12-03 20:26:15 +0000210
211 /// A flag to remember whether the implicit forms of operator new and delete
212 /// have been declared.
213 bool GlobalNewDeleteDeclared;
Steve Naroff7f549f12007-10-10 21:53:07 +0000214
Steve Naroff5811baf2007-10-14 00:58:41 +0000215 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000216 struct ObjCMethodList {
217 ObjCMethodDecl *Method;
218 ObjCMethodList *Next;
Steve Naroff5811baf2007-10-14 00:58:41 +0000219
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000220 ObjCMethodList() {
Steve Naroff5811baf2007-10-14 00:58:41 +0000221 Method = 0;
222 Next = 0;
223 }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000224 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff5811baf2007-10-14 00:58:41 +0000225 Method = M;
226 Next = C;
227 }
228 };
229 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
230 /// messages to "id". We need to maintain a list, since selectors can have
231 /// differing signatures across classes. In Cocoa, this happens to be
232 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000233 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
234 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Chris Lattner7cee11f2006-11-03 06:42:29 +0000235public:
Chris Lattnerfe0e0af2008-02-06 00:46:58 +0000236 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000237
Chris Lattnerac18be92006-11-20 06:49:47 +0000238 const LangOptions &getLangOptions() const;
Chris Lattnerbc495d72008-11-22 08:28:49 +0000239 Diagnostic &getDiagnostics() const { return Diags; }
240 SourceManager &getSourceManager() const { return SourceMgr; }
241
Chris Lattner84f1ee32008-11-18 21:53:24 +0000242 /// The primitive diagnostic helpers.
Chris Lattnerbc495d72008-11-22 08:28:49 +0000243 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
244 return Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
245 }
Steve Naroff71ce2e02007-05-18 22:53:50 +0000246
Chris Lattner57c523f2007-08-31 04:53:24 +0000247 virtual void DeleteExpr(ExprTy *E);
248 virtual void DeleteStmt(StmtTy *S);
249
Sebastian Redlc675bab2008-12-13 16:23:55 +0000250 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
251 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
252
Chris Lattnerf4404402008-08-23 03:19:52 +0000253 virtual void ActOnEndOfTranslationUnit();
254
Chris Lattner7cee11f2006-11-03 06:42:29 +0000255 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000256 // Type Analysis / Processing: SemaType.cpp.
257 //
Chris Lattner4b413ea2008-06-26 06:27:57 +0000258 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnera7e619c2008-06-29 00:50:08 +0000259 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Sebastian Redl351bb782008-12-02 14:43:59 +0000260 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor92751d42008-11-17 22:58:34 +0000261 DeclarationName GetNameForDeclarator(Declarator &D);
262
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000263 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian56ff1462007-11-08 23:49:49 +0000264
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000265 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
266
Sebastian Redl351bb782008-12-02 14:43:59 +0000267 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redl842ef522008-11-08 13:00:26 +0000268
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000269 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000270 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000271 //
Douglas Gregorae2fbad2008-11-17 20:34:05 +0000272 virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S,
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +0000273 const CXXScopeSpec *SS);
Douglas Gregorad590502008-12-15 23:53:10 +0000274 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) {
275 return ActOnDeclarator(S, D, LastInGroup, false);
276 }
277 DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
278 bool IsFunctionDefinition);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000279 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
280 virtual void ActOnParamDefaultArgument(DeclTy *param,
281 SourceLocation EqualLoc,
282 ExprTy *defarg);
Douglas Gregor58354032008-12-24 00:01:03 +0000283 virtual void ActOnParamUnparsedDefaultArgument(DeclTy *param,
284 SourceLocation EqualLoc);
Douglas Gregor4d87df52008-12-16 21:30:33 +0000285 virtual void ActOnParamDefaultArgumentError(DeclTy *param);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000286 virtual void AddInitializerToDecl(DeclTy *dcl, ExprArg init);
287 void AddInitializerToDecl(DeclTy *dcl, ExprArg init, bool DirectInit);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000288 void ActOnUninitializedDecl(DeclTy *dcl);
Chris Lattner776fac82007-06-09 00:53:06 +0000289 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
290
Chris Lattnera55a2cc2007-10-09 17:14:05 +0000291 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000292 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000293 virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D);
Steve Naroffb313fc32007-11-11 23:20:51 +0000294
Sebastian Redlc675bab2008-12-13 16:23:55 +0000295 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtArg Body);
Sebastian Redlc675bab2008-12-13 16:23:55 +0000296 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson5c6c0592008-02-08 00:33:21 +0000297
Steve Naroffc62adb62007-10-09 22:01:59 +0000298 /// Scope actions.
299 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
300 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000301
Chris Lattner200bdc32006-11-19 02:43:37 +0000302 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
303 /// no declarator (e.g. "struct foo;") is parsed.
Sebastian Redla2b5e312008-12-28 15:28:59 +0000304 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner200bdc32006-11-19 02:43:37 +0000305
Douglas Gregor9ac7a072009-01-07 00:43:41 +0000306 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
307 RecordDecl *AnonRecord);
308 virtual DeclTy *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
309 RecordDecl *Record);
310
Steve Naroff30d242c2007-09-15 18:49:24 +0000311 virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +0000312 SourceLocation KWLoc, const CXXScopeSpec &SS,
313 IdentifierInfo *Name, SourceLocation NameLoc,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +0000314 AttributeList *Attr,
315 MultiTemplateParamsArg TemplateParameterLists);
Ted Kremenek21475702008-09-05 17:16:31 +0000316
Douglas Gregor91f84212008-12-11 16:49:14 +0000317 virtual void ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner2cc35ae2008-08-23 02:00:52 +0000318 IdentifierInfo *ClassName,
319 llvm::SmallVectorImpl<DeclTy*> &Decls);
Douglas Gregor91f84212008-12-11 16:49:14 +0000320 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
Chris Lattner1300fb92007-01-23 23:42:53 +0000321 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000322
323 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
324 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian96376742008-04-11 16:55:42 +0000325 tok::ObjCKeywordKind visibility);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000326
Steve Naroff2e688fd2007-09-14 23:09:53 +0000327 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000328 virtual void ActOnFields(Scope* S,
Steve Naroff33a1e802007-10-29 21:38:07 +0000329 SourceLocation RecLoc, DeclTy *TagDecl,
330 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar15619c72008-10-03 02:03:53 +0000331 SourceLocation LBrac, SourceLocation RBrac,
332 AttributeList *AttrList);
Douglas Gregor82ac25e2009-01-08 20:45:30 +0000333
334 /// ActOnTagStartDefinition - Invoked when we have entered the
335 /// scope of a tag's definition (e.g., for an enumeration, class,
336 /// struct, or union).
337 virtual void ActOnTagStartDefinition(Scope *S, DeclTy *TagDecl);
338
339 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
340 /// the definition of a tag (enumeration, class, struct, or union).
341 virtual void ActOnTagFinishDefinition(Scope *S, DeclTy *TagDecl);
342
Steve Naroff30d242c2007-09-15 18:49:24 +0000343 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000344 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000345 SourceLocation IdLoc, IdentifierInfo *Id,
346 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff30d242c2007-09-15 18:49:24 +0000347 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000348 DeclTy **Elements, unsigned NumElements);
Sebastian Redl842ef522008-11-08 13:00:26 +0000349
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +0000350 DeclContext *getContainingDC(DeclContext *DC);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000351
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000352 /// Set the current declaration context until it gets popped.
Douglas Gregor91f84212008-12-11 16:49:14 +0000353 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000354 void PopDeclContext();
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +0000355
Chris Lattner79413952008-12-04 23:50:19 +0000356 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
357 /// to the function decl for the function being parsed. If we're currently
358 /// in a 'block', this returns the containing context.
359 FunctionDecl *getCurFunctionDecl();
360
361 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
362 /// the method decl for the method being parsed. If we're currently
363 /// in a 'block', this returns the containing context.
Daniel Dunbar6e8aa532008-08-11 05:35:13 +0000364 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000365
Chris Lattner79413952008-12-04 23:50:19 +0000366 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
367 /// or C function we're in, otherwise return null. If we're currently
368 /// in a 'block', this returns the containing context.
369 NamedDecl *getCurFunctionOrMethodDecl();
370
Argyrios Kyrtzidisb8a49202008-04-12 00:47:19 +0000371 /// Add this decl to the scope shadowed decl chains.
372 void PushOnScopeChains(NamedDecl *D, Scope *S);
373
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000374 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
375 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
376 /// true if 'D' belongs to the given declaration context.
377 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor91f84212008-12-11 16:49:14 +0000378 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argyrios Kyrtzidis5b144d52008-09-09 21:18:04 +0000379 }
380
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000381 /// Subroutines of ActOnDeclarator().
Chris Lattner07b201d2007-11-14 06:34:38 +0000382 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
383 ScopedDecl *LastDecl);
Steve Naroff257520b2008-04-01 23:04:06 +0000384 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
Douglas Gregor89f238c2008-04-21 02:02:58 +0000385 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old,
386 bool &Redeclaration);
Steve Naroff257520b2008-04-01 23:04:06 +0000387 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000388 FunctionDecl *MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroff5bb8f222008-08-08 17:50:35 +0000389 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000390
391 /// C++ Overloading.
392 bool IsOverload(FunctionDecl *New, Decl* OldD,
393 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregor2fe98832008-11-03 19:09:14 +0000394 ImplicitConversionSequence
395 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000396 bool SuppressUserConversions = false,
397 bool AllowExplicit = false);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000398 bool IsStandardConversion(Expr *From, QualType ToType,
399 StandardConversionSequence& SCS);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000400 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
401 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
402 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +0000403 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregora119f102008-12-19 19:13:09 +0000404 bool isObjCPointerConversion(QualType FromType, QualType ToType,
405 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor39c16d42008-10-24 04:54:22 +0000406 bool CheckPointerConversion(Expr *From, QualType ToType);
Douglas Gregor9a657932008-10-21 23:43:52 +0000407 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregor26bee0b2008-10-31 16:23:19 +0000408 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000409 UserDefinedConversionSequence& User,
410 bool AllowExplicit = false);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000411
412 ImplicitConversionSequence::CompareKind
413 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
414 const ImplicitConversionSequence& ICS2);
415
416 ImplicitConversionSequence::CompareKind
417 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
418 const StandardConversionSequence& SCS2);
419
Douglas Gregore1eb9d82008-10-22 14:17:15 +0000420 ImplicitConversionSequence::CompareKind
421 CompareQualificationConversions(const StandardConversionSequence& SCS1,
422 const StandardConversionSequence& SCS2);
423
Douglas Gregor5c407d92008-10-23 00:40:37 +0000424 ImplicitConversionSequence::CompareKind
425 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
426 const StandardConversionSequence& SCS2);
427
Douglas Gregor2fe98832008-11-03 19:09:14 +0000428 ImplicitConversionSequence
429 TryCopyInitialization(Expr* From, QualType ToType,
430 bool SuppressUserConversions = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +0000431 bool PerformCopyInitialization(Expr *&From, QualType ToType,
432 const char *Flavor);
433
Douglas Gregor436424c2008-11-18 23:14:02 +0000434 ImplicitConversionSequence
435 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
436 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
437
Douglas Gregor5fb53972009-01-14 15:45:31 +0000438 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
439 bool PerformContextuallyConvertToBool(Expr *&From);
440
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000441 /// OverloadingResult - Capture the result of performing overload
442 /// resolution.
443 enum OverloadingResult {
444 OR_Success, ///< Overload resolution succeeded.
445 OR_No_Viable_Function, ///< No viable function found.
446 OR_Ambiguous ///< Ambiguous candidates found.
447 };
448
449 void AddOverloadCandidate(FunctionDecl *Function,
450 Expr **Args, unsigned NumArgs,
Douglas Gregor2fe98832008-11-03 19:09:14 +0000451 OverloadCandidateSet& CandidateSet,
452 bool SuppressUserConversions = false);
Douglas Gregor436424c2008-11-18 23:14:02 +0000453 void AddMethodCandidate(CXXMethodDecl *Method,
454 Expr *Object, Expr **Args, unsigned NumArgs,
455 OverloadCandidateSet& CandidateSet,
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000456 bool SuppressUserConversions = false);
Douglas Gregora1f013e2008-11-07 22:36:19 +0000457 void AddConversionCandidate(CXXConversionDecl *Conversion,
458 Expr *From, QualType ToType,
459 OverloadCandidateSet& CandidateSet);
Douglas Gregorab7897a2008-11-19 22:57:39 +0000460 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
461 const FunctionTypeProto *Proto,
462 Expr *Object, Expr **Args, unsigned NumArgs,
463 OverloadCandidateSet& CandidateSet);
Douglas Gregor436424c2008-11-18 23:14:02 +0000464 void AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
465 Expr **Args, unsigned NumArgs,
466 OverloadCandidateSet& CandidateSet);
Douglas Gregora11693b2008-11-12 17:17:38 +0000467 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
468 Expr **Args, unsigned NumArgs,
Douglas Gregorc5e61072009-01-13 00:52:54 +0000469 OverloadCandidateSet& CandidateSet,
Douglas Gregor5fb53972009-01-14 15:45:31 +0000470 bool IsAssignmentOperator = false,
471 unsigned NumContextualBoolArguments = 0);
Douglas Gregord08452f2008-11-19 15:42:04 +0000472 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
473 Expr **Args, unsigned NumArgs,
474 OverloadCandidateSet& CandidateSet);
Douglas Gregorc28b57d2008-11-03 20:45:27 +0000475 void AddOverloadCandidates(const OverloadedFunctionDecl *Ovl,
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000476 Expr **Args, unsigned NumArgs,
Douglas Gregor2fe98832008-11-03 19:09:14 +0000477 OverloadCandidateSet& CandidateSet,
478 bool SuppressUserConversions = false);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000479 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
480 const OverloadCandidate& Cand2);
481 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
482 OverloadCandidateSet::iterator& Best);
483 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
484 bool OnlyViable);
485
Douglas Gregorcd695e52008-11-10 20:40:00 +0000486 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
487 bool Complain);
488 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
489
Douglas Gregora60a6912008-11-26 06:01:48 +0000490 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, OverloadedFunctionDecl *Ovl,
491 SourceLocation LParenLoc,
492 Expr **Args, unsigned NumArgs,
493 SourceLocation *CommaLocs,
494 SourceLocation RParenLoc);
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000495 ExprResult
496 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
497 SourceLocation LParenLoc, Expr **Args,
498 unsigned NumArgs, SourceLocation *CommaLocs,
499 SourceLocation RParenLoc);
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000500 ExprResult
Douglas Gregorb0846b02008-12-06 00:22:45 +0000501 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor91cea0a2008-11-19 21:05:33 +0000502 Expr **Args, unsigned NumArgs,
503 SourceLocation *CommaLocs,
504 SourceLocation RParenLoc);
Douglas Gregor5251f1b2008-10-21 16:13:35 +0000505
Douglas Gregor55297ac2008-12-23 00:26:44 +0000506 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregore0e79bd2008-11-20 16:27:02 +0000507 SourceLocation MemberLoc,
508 IdentifierInfo &Member);
Douglas Gregor5fb53972009-01-14 15:45:31 +0000509
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000510 /// Helpers for dealing with function parameters.
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000511 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000512 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregorcaa8ace2008-05-07 04:49:29 +0000513 void CheckExtraCXXDefaultArguments(Declarator &D);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000514
Douglas Gregord7c4d982008-12-30 03:27:21 +0000515 // FIXME: NamespaceNameOnly parameter is added temporarily
516 // we will need a better way to specify lookup criteria for things
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000517 // like template specializations, explicit template instantiations, etc.
Douglas Gregord7c4d982008-12-30 03:27:21 +0000518
Douglas Gregor45a33ec2009-01-12 18:45:55 +0000519 Scope *getNonFieldDeclScope(Scope *S);
520
Douglas Gregor34074322009-01-14 22:20:51 +0000521 /// \name Name lookup
522 ///
523 /// These routines provide name lookup that is used during semantic
524 /// analysis to resolve the various kinds of names (identifiers,
525 /// overloaded operator names, constructor names, etc.) into zero or
526 /// more declarations within a particular scope. The major entry
527 /// points are LookupName, which performs unqualified name lookup,
528 /// and LookupQualifiedName, which performs qualified name lookup.
529 ///
530 /// All name lookup is performed based on some specific criteria,
531 /// which specify what names will be visible to name lookup and how
532 /// far name lookup should work. These criteria are important both
533 /// for capturing language semantics (certain lookups will ignore
534 /// certain names, for example) and for performance, since name
535 /// lookup is often a bottleneck in the compilation of C++. Name
536 /// lookup criteria is specified via the LookupCriteria class.
537 ///
538 /// The results of name lookup can vary based on the kind of name
539 /// lookup performed, the current language, and the translation
540 /// unit. In C, for example, name lookup will either return nothing
541 /// (no entity found) or a single declaration. In C++, name lookup
542 /// can additionally refer to a set of overloaded functions or
543 /// result in an ambiguity. All of the possible results of name
544 /// lookup are captured by the LookupResult class, which provides
545 /// the ability to distinguish among them.
546 //@{
Douglas Gregord7c4d982008-12-30 03:27:21 +0000547
Douglas Gregor34074322009-01-14 22:20:51 +0000548 /// @brief Describes the criteria by which name lookup will
549 /// determine whether a given name will be found.
550 ///
551 /// The LookupCriteria class captures the information required to
552 /// direct name lookup to find the appropriate kind of name. It
553 /// includes information about which kinds of names to consider
554 /// (ordinary names, tag names, class/struct/union member names,
555 /// namespace names, etc.) and where to look for those
556 /// names. LookupCriteria is used throughout semantic analysis to
557 /// specify how to search for a name, e.g., with the LookupName and
558 /// LookupQualifiedName functions.
559 struct LookupCriteria {
560 /// NameKind - The kinds of names that we are looking for.
561 enum NameKind {
562 /// Ordinary - Ordinary name lookup, which finds ordinary names
563 /// (functions, variables, typedefs, etc.) in C and most kinds
564 /// of names (functions, variables, members, types, etc.) in
565 /// C++.
566 Ordinary,
567 /// Tag - Tag name lookup, which finds the names of enums,
568 /// classes, structs, and unions.
569 Tag,
570 /// Member - Member name lookup, which finds the names of
571 /// class/struct/union members.
572 Member,
573 /// NestedNameSpecifier - Look up of a name that precedes the
574 /// '::' scope resolution operator in C++. This lookup
575 /// completely ignores operator, function, and enumerator names
576 /// (C++ [basic.lookup.qual]p1).
577 NestedNameSpecifier,
578 /// Namespace - Look up a namespace name within a C++
579 /// using directive or namespace alias definition, ignoring
580 /// non-namespace names (C++ [basic.lookup.udir]p1).
581 Namespace
582 } Kind;
583
584 /// AllowLazyBuiltinCreation - If true, permits name lookup to
585 /// lazily build declarations for built-in names, e.g.,
586 /// __builtin_expect.
587 bool AllowLazyBuiltinCreation;
588
589 /// RedeclarationOnly - If true, the lookup will only
590 /// consider entities within the scope where the lookup
591 /// began. Entities that might otherwise meet the lookup criteria
592 /// but are not within the original lookup scope will be ignored.
593 bool RedeclarationOnly;
594
595 /// IDNS - Bitwise OR of the appropriate Decl::IDNS_* flags that
596 /// describe the namespaces where we should look for names. This
597 /// field is determined by the kind of name we're searching for.
598 unsigned IDNS;
599
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000600 LookupCriteria()
601 : Kind(Ordinary), AllowLazyBuiltinCreation(true),
602 RedeclarationOnly(false), IDNS(Decl::IDNS_Ordinary) { }
603
Douglas Gregor34074322009-01-14 22:20:51 +0000604 LookupCriteria(NameKind K, bool RedeclarationOnly, bool CPlusPlus);
605
606 bool isLookupResult(Decl *D) const;
607 };
608
609 /// @brief Represents the results of name lookup.
610 ///
611 /// An instance of the LookupResult class captures the results of a
612 /// single name lookup, which can return no result (nothing found),
613 /// a single declaration, a set of overloaded functions, or an
614 /// ambiguity. Use the getKind() method to determine which of these
615 /// results occurred for a given lookup.
616 ///
617 /// Any non-ambiguous lookup can be converted into a single
618 /// (possibly NULL) @c Decl* via a conversion function or the
619 /// getAsDecl() method. This conversion permits the common-case
620 /// usage in C and Objective-C where name lookup will always return
621 /// a single declaration.
622 class LookupResult {
623 /// The kind of entity that is actually stored within the
624 /// LookupResult object.
625 mutable enum {
626 /// First is a single declaration (a Decl*), which may be NULL.
627 SingleDecl,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000628
Douglas Gregor34074322009-01-14 22:20:51 +0000629 /// [First, Last) is an iterator range represented as opaque
630 /// pointers used to reconstruct IdentifierResolver::iterators.
631 OverloadedDeclFromIdResolver,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000632
Douglas Gregor34074322009-01-14 22:20:51 +0000633 /// [First, Last) is an iterator range represented as opaque
634 /// pointers used to reconstruct DeclContext::lookup_iterators.
635 OverloadedDeclFromDeclContext,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000636
637 /// First is a pointer to a BasePaths structure, which is owned
638 /// by the LookupResult. Last is non-zero to indicate that the
639 /// ambiguity is caused by two names found in base class
640 /// subobjects of different types.
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000641 AmbiguousLookup,
642
643 /// We've moved from this object. There should not be any
644 /// attempts to look at its state.
645 Dead
Douglas Gregor34074322009-01-14 22:20:51 +0000646 } StoredKind;
647
648 /// The first lookup result, whose contents depend on the kind of
649 /// lookup result. This may be a Decl* (if StoredKind ==
650 /// SingleDecl), the opaque pointer from an
651 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000652 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
653 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
654 /// BasePaths pointer (if StoredKind == AmbiguousLookup).
Douglas Gregor34074322009-01-14 22:20:51 +0000655 mutable uintptr_t First;
656
657 /// The last lookup result, whose contents depend on the kind of
658 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000659 /// SingleDecl), it may have the same type as First (for
660 /// overloaded function declarations), or is may be used as a
661 /// Boolean value (if StoredKind == AmbiguousLookup).
Douglas Gregor34074322009-01-14 22:20:51 +0000662 mutable uintptr_t Last;
663
664 /// Context - The context in which we will build any
665 /// OverloadedFunctionDecl nodes needed by the conversion to
666 /// Decl*.
667 ASTContext *Context;
668
669 public:
670 /// @brief The kind of entity found by name lookup.
671 enum LookupKind {
672 /// @brief No entity found met the criteria.
673 NotFound = 0,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000674
Douglas Gregor34074322009-01-14 22:20:51 +0000675 /// @brief Name lookup found a single declaration that met the
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000676 /// criteria. getAsDecl will return this declaration.
Douglas Gregor34074322009-01-14 22:20:51 +0000677 Found,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000678
Douglas Gregor34074322009-01-14 22:20:51 +0000679 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000680 /// met the criteria. getAsDecl will turn this set of overloaded
681 /// functions into an OverloadedFunctionDecl.
Douglas Gregor34074322009-01-14 22:20:51 +0000682 FoundOverloaded,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000683
684 /// Name lookup results in an ambiguity because multiple
685 /// entities that meet the lookup criteria were found in
686 /// subobjects of different types. For example:
687 /// @code
688 /// struct A { void f(int); }
689 /// struct B { void f(double); }
690 /// struct C : A, B { };
691 /// void test(C c) {
692 /// c.f(0); // error: A::f and B::f come from subobjects of different
693 /// // types. overload resolution is not performed.
694 /// }
695 /// @endcode
696 AmbiguousBaseSubobjectTypes,
697
698 /// Name lookup results in an ambiguity because multiple
699 /// nonstatic entities that meet the lookup criteria were found
700 /// in different subobjects of the same type. For example:
701 /// @code
702 /// struct A { int x; };
703 /// struct B : A { };
704 /// struct C : A { };
705 /// struct D : B, C { };
706 /// int test(D d) {
707 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
708 /// }
709 /// @endcode
710 AmbiguousBaseSubobjects
Douglas Gregor34074322009-01-14 22:20:51 +0000711 };
712
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000713 LookupResult() : StoredKind(Dead), First(0), Last(0), Context(0) { }
714
715 LookupResult(const LookupResult& Other);
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000716
Douglas Gregor34074322009-01-14 22:20:51 +0000717 LookupResult(ASTContext &Context, Decl *D)
718 : StoredKind(SingleDecl), First(reinterpret_cast<uintptr_t>(D)),
719 Last(0), Context(&Context) { }
720
721 LookupResult(ASTContext &Context,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000722 IdentifierResolver::iterator F, IdentifierResolver::iterator L);
Douglas Gregor34074322009-01-14 22:20:51 +0000723
724 LookupResult(ASTContext &Context,
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000725 DeclContext::lookup_iterator F, DeclContext::lookup_iterator L);
726
727 LookupResult(ASTContext &Context, BasePaths *Paths,
728 bool DifferentSubobjectTypes)
729 : StoredKind(AmbiguousLookup),
730 First(reinterpret_cast<uintptr_t>(Paths)),
731 Last(DifferentSubobjectTypes? 1 : 0),
Douglas Gregor34074322009-01-14 22:20:51 +0000732 Context(&Context) { }
733
Douglas Gregor41c8ba82009-01-15 02:19:31 +0000734 ~LookupResult();
735
736 LookupResult& operator=(const LookupResult& Other);
737
Douglas Gregor34074322009-01-14 22:20:51 +0000738 LookupKind getKind() const;
739
740 /// @brief Determine whether name look found something.
741 operator bool() const { return getKind() != NotFound; }
742
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000743 /// @brief Determines whether the lookup resulted in an ambiguity.
744 bool isAmbiguous() const { return StoredKind == AmbiguousLookup; }
745
Douglas Gregor34074322009-01-14 22:20:51 +0000746 /// @brief Allows conversion of a lookup result into a
747 /// declaration, with the same behavior as getAsDecl.
748 operator Decl*() const { return getAsDecl(); }
749
750 Decl* getAsDecl() const;
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000751
752 BasePaths *getBasePaths() const;
Douglas Gregor34074322009-01-14 22:20:51 +0000753 };
754
755 LookupResult LookupName(Scope *S, DeclarationName Name,
756 LookupCriteria Criteria);
757 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
758 LookupCriteria Criteria);
759 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec &SS,
760 DeclarationName Name, LookupCriteria Criteria);
Douglas Gregor34074322009-01-14 22:20:51 +0000761 LookupResult LookupDecl(DeclarationName Name, unsigned NSI, Scope *S,
762 const DeclContext *LookupCtx = 0,
763 bool enableLazyBuiltinCreation = true,
764 bool LookInParent = true,
765 bool NamespaceNameOnly = false);
Douglas Gregor960b5bc2009-01-15 00:26:24 +0000766
767 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
768 SourceLocation NameLoc,
769 SourceRange LookupRange = SourceRange());
Douglas Gregor34074322009-01-14 22:20:51 +0000770 //@}
771
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000772 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Steve Naroff2fc93f52008-04-02 14:35:35 +0000773 ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
774 Scope *S);
Steve Naroff2f742082007-09-16 16:16:00 +0000775 ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Steve Naroff3273c222007-03-14 21:52:03 +0000776 Scope *S);
Douglas Gregor34074322009-01-14 22:20:51 +0000777
778 // More parsing and symbol table subroutines.
779
Steve Naroffa8fd9732007-06-11 00:35:03 +0000780 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner58418ff2008-06-29 00:16:31 +0000781 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnera5741542008-06-28 23:58:55 +0000782 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000783
Steve Naroff15833ed2008-02-10 21:38:56 +0000784 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
785 bool &IncompleteImpl);
Fariborz Jahanian7988d7d2008-12-05 18:18:52 +0000786 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
787 ObjCMethodDecl *IntfMethod);
Sebastian Redlc4704762008-11-11 11:37:55 +0000788
789 NamespaceDecl *GetStdNamespace();
Fariborz Jahanian8e1555c2009-01-12 19:55:42 +0000790
791 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
792 ObjCInterfaceDecl *IDecl) const;
Steve Naroff15833ed2008-02-10 21:38:56 +0000793
Chris Lattnerce1da2c2009-01-06 07:27:21 +0000794 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000795 /// methods declared in protocol, and those referenced by it.
796 /// \param IDecl - Used for checking for methods which may have been
797 /// inherited.
Steve Naroffa36992242008-02-08 22:06:17 +0000798 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
799 ObjCProtocolDecl *PDecl,
Fariborz Jahanianadf84f32007-10-02 20:06:01 +0000800 bool& IncompleteImpl,
Steve Naroff71c3c1c2007-10-08 21:05:34 +0000801 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbarc7dfbfd2008-09-04 20:01:15 +0000802 const llvm::DenseSet<Selector> &ClsMap,
803 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000804
Steve Naroffd1741552007-10-02 21:43:37 +0000805 /// CheckImplementationIvars - This routine checks if the instance variables
806 /// listed in the implelementation match those listed in the interface.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000807 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
808 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff15833ed2008-02-10 21:38:56 +0000809 SourceLocation Loc);
Steve Naroffd1741552007-10-02 21:43:37 +0000810
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000811 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
812 /// remains unimplemented in the @implementation class.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000813 void ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
814 ObjCInterfaceDecl* IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000815
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +0000816 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
817 /// category interface is implemented in the category @implementation.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000818 void ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
819 ObjCCategoryDecl *CatClassDecl);
Fariborz Jahanian458f7112007-10-05 18:00:57 +0000820 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
821 /// true, or false, accordingly.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000822 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffa0ed1652008-10-21 10:37:50 +0000823 const ObjCMethodDecl *PrevMethod,
824 bool matchBasedOnSizeAndAlignment = false);
Steve Naroff7f549f12007-10-10 21:53:07 +0000825
Steve Naroff5811baf2007-10-14 00:58:41 +0000826 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
827 /// unit are added to a global pool. This allows us to efficiently associate
828 /// a selector with a method declaraation for purposes of typechecking
829 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000830 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff5811baf2007-10-14 00:58:41 +0000831
Steve Naroff4a82d812008-09-30 14:38:43 +0000832 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
833 /// there are multiple signatures.
834 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
835
Steve Naroff5811baf2007-10-14 00:58:41 +0000836 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000837 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000838 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000839 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +0000840public:
Sebastian Redl52f03ba2008-12-21 12:04:03 +0000841 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
842
843 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
844 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
845 MultiStmtArg Elts,
846 bool isStmtExpr);
847 virtual OwningStmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
848 SourceLocation EndLoc);
Sebastian Redl1cbb59182008-12-28 16:13:43 +0000849 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
850 SourceLocation DotDotDotLoc, ExprArg RHSVal,
851 SourceLocation ColonLoc, StmtArg SubStmt);
852 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
853 SourceLocation ColonLoc,
854 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl6a8002e2009-01-11 00:38:46 +0000855 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
856 IdentifierInfo *II,
857 SourceLocation ColonLoc,
858 StmtArg SubStmt);
859 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
860 StmtArg ThenVal, SourceLocation ElseLoc,
861 StmtArg ElseVal);
862 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
863 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
864 StmtArg Switch, StmtArg Body);
Steve Naroff66356bd2007-09-16 14:56:35 +0000865 virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
Chris Lattner85ed8732006-11-04 20:40:44 +0000866 StmtTy *Body);
Steve Naroff66356bd2007-09-16 14:56:35 +0000867 virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner85ed8732006-11-04 20:40:44 +0000868 SourceLocation WhileLoc, ExprTy *Cond);
869
Steve Naroff66356bd2007-09-16 14:56:35 +0000870 virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
Chris Lattner71e23ce2006-11-04 20:18:38 +0000871 SourceLocation LParenLoc,
872 StmtTy *First, ExprTy *Second, ExprTy *Third,
873 SourceLocation RParenLoc, StmtTy *Body);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000874 virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
Fariborz Jahanian732b8c22008-01-03 17:55:25 +0000875 SourceLocation LParenLoc,
876 StmtTy *First, ExprTy *Second,
877 SourceLocation RParenLoc, StmtTy *Body);
878
Steve Naroff66356bd2007-09-16 14:56:35 +0000879 virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
Chris Lattner16976d32006-11-05 01:46:01 +0000880 SourceLocation LabelLoc,
881 IdentifierInfo *LabelII);
Steve Naroff66356bd2007-09-16 14:56:35 +0000882 virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattner16976d32006-11-05 01:46:01 +0000883 SourceLocation StarLoc,
884 ExprTy *DestExp);
Steve Naroff66356bd2007-09-16 14:56:35 +0000885 virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Chris Lattnereaafe1222006-11-10 05:17:58 +0000886 Scope *CurScope);
Steve Naroff66356bd2007-09-16 14:56:35 +0000887 virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Chris Lattner71e23ce2006-11-04 20:18:38 +0000888
Steve Naroff66356bd2007-09-16 14:56:35 +0000889 virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000890 ExprTy *RetValExp);
Steve Naroffc540d662008-09-03 18:15:37 +0000891 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000892
Anders Carlsson81a5a692007-11-20 19:21:03 +0000893 virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
Anders Carlsson19fe1162008-02-05 23:03:50 +0000894 bool IsSimple,
Anders Carlsson660bdd12007-11-23 23:12:25 +0000895 bool IsVolatile,
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000896 unsigned NumOutputs,
897 unsigned NumInputs,
898 std::string *Names,
899 ExprTy **Constraints,
900 ExprTy **Exprs,
Anders Carlsson81a5a692007-11-20 19:21:03 +0000901 ExprTy *AsmString,
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000902 unsigned NumClobbers,
903 ExprTy **Clobbers,
Chris Lattner73c56c02007-10-29 04:04:16 +0000904 SourceLocation RParenLoc);
905
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000906 virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
Fariborz Jahanian9e63b982007-11-01 23:59:59 +0000907 SourceLocation RParen, StmtTy *Parm,
908 StmtTy *Body, StmtTy *CatchList);
909
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000910 virtual StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
Fariborz Jahanian71234d82007-11-02 00:18:53 +0000911 StmtTy *Body);
912
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000913 virtual StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
Fariborz Jahanianf859ef22007-11-02 15:39:31 +0000914 StmtTy *Try,
915 StmtTy *Catch, StmtTy *Finally);
916
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000917 virtual StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000918 StmtTy *Throw);
Fariborz Jahanian48085b82008-01-29 19:14:59 +0000919 virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
920 ExprTy *SynchExpr,
921 StmtTy *SynchBody);
Sebastian Redlb219c902008-12-21 16:41:36 +0000922
Sebastian Redl54c04d42008-12-22 19:15:10 +0000923 virtual DeclTy *ActOnExceptionDeclarator(Scope *S, Declarator &D);
924 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
925 DeclTy *ExDecl,
926 StmtArg HandlerBlock);
Sebastian Redl9b244a82008-12-22 21:35:02 +0000927 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
928 StmtArg TryBlock,
929 MultiStmtArg Handlers);
Sebastian Redlb219c902008-12-21 16:41:36 +0000930
Chris Lattner7cee11f2006-11-03 06:42:29 +0000931 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000932 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000933
934 // Primary Expressions.
Steve Naroff30d242c2007-09-15 18:49:24 +0000935 virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
Chris Lattnerac18be92006-11-20 06:49:47 +0000936 IdentifierInfo &II,
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +0000937 bool HasTrailingLParen,
938 const CXXScopeSpec *SS = 0);
Douglas Gregor7911b372008-11-19 19:09:45 +0000939 virtual ExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
940 SourceLocation OperatorLoc,
941 OverloadedOperatorKind Op,
942 bool HasTrailingLParen,
943 const CXXScopeSpec &SS);
944 virtual ExprResult ActOnCXXConversionFunctionExpr(Scope *S,
945 SourceLocation OperatorLoc,
946 TypeTy *Ty,
947 bool HasTrailingLParen,
948 const CXXScopeSpec &SS);
Douglas Gregorc7acfdf2009-01-06 05:10:23 +0000949 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
950 bool TypeDependent, bool ValueDependent,
951 const CXXScopeSpec *SS = 0);
Douglas Gregor9ac7a072009-01-07 00:43:41 +0000952 ExprResult
953 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
954 FieldDecl *Field,
955 Expr *BaseObjectExpr = 0,
956 SourceLocation OpLoc = SourceLocation());
Douglas Gregor4ea80432008-11-18 15:03:34 +0000957 ExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
958 DeclarationName Name,
959 bool HasTrailingLParen,
Douglas Gregorb0846b02008-12-06 00:22:45 +0000960 const CXXScopeSpec *SS,
961 bool ForceResolution = false);
Douglas Gregor4ea80432008-11-18 15:03:34 +0000962
963
Chris Lattner6307f192008-08-10 01:53:14 +0000964 virtual ExprResult ActOnPredefinedExpr(SourceLocation Loc,
965 tok::TokenKind Kind);
Steve Naroff83895f72007-09-16 03:34:24 +0000966 virtual ExprResult ActOnNumericConstant(const Token &);
967 virtual ExprResult ActOnCharacterConstant(const Token &);
968 virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000969 ExprTy *Val);
Chris Lattner697e5d62006-11-09 06:32:27 +0000970
Steve Naroff83895f72007-09-16 03:34:24 +0000971 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +0000972 /// fragments (e.g. "foo" "bar" L"baz").
Steve Naroff83895f72007-09-16 03:34:24 +0000973 virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
Chris Lattner697e5d62006-11-09 06:32:27 +0000974
Chris Lattner7cee11f2006-11-03 06:42:29 +0000975 // Binary/Unary Operators. 'Tok' is the token for the operator.
Douglas Gregord08452f2008-11-19 15:42:04 +0000976 virtual ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
977 tok::TokenKind Op, ExprTy *Input);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000978 virtual ExprResult
Sebastian Redl6f282892008-11-11 17:56:53 +0000979 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
980 void *TyOrEx, const SourceRange &ArgRange);
981
982 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
983 const SourceRange &R, bool isSizeof);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000984
Douglas Gregord08452f2008-11-19 15:42:04 +0000985 virtual ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000986 tok::TokenKind Kind, ExprTy *Input);
987
Douglas Gregor40412ac2008-11-19 17:17:41 +0000988 virtual ExprResult ActOnArraySubscriptExpr(Scope *S, ExprTy *Base,
989 SourceLocation LLoc, ExprTy *Idx,
990 SourceLocation RLoc);
Douglas Gregor55297ac2008-12-23 00:26:44 +0000991 virtual ExprResult ActOnMemberReferenceExpr(Scope *S, ExprTy *Base,
992 SourceLocation OpLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000993 tok::TokenKind OpKind,
994 SourceLocation MemberLoc,
995 IdentifierInfo &Member);
Douglas Gregor97fd6e22008-12-22 05:46:06 +0000996 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
997 FunctionDecl *FDecl,
998 const FunctionTypeProto *Proto,
999 Expr **Args, unsigned NumArgs,
1000 SourceLocation RParenLoc);
Chris Lattner7cee11f2006-11-03 06:42:29 +00001001
Steve Naroff83895f72007-09-16 03:34:24 +00001002 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner7cee11f2006-11-03 06:42:29 +00001003 /// This provides the location of the left/right parens and a list of comma
1004 /// locations.
Douglas Gregorb0846b02008-12-06 00:22:45 +00001005 virtual ExprResult ActOnCallExpr(Scope *S, ExprTy *Fn,
1006 SourceLocation LParenLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +00001007 ExprTy **Args, unsigned NumArgs,
1008 SourceLocation *CommaLocs,
1009 SourceLocation RParenLoc);
1010
Steve Naroff83895f72007-09-16 03:34:24 +00001011 virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner7cee11f2006-11-03 06:42:29 +00001012 SourceLocation RParenLoc, ExprTy *Op);
Steve Narofffbd09832007-07-19 01:06:55 +00001013
Steve Naroff83895f72007-09-16 03:34:24 +00001014 virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
Steve Narofffbd09832007-07-19 01:06:55 +00001015 SourceLocation RParenLoc, ExprTy *Op);
Chris Lattner7cee11f2006-11-03 06:42:29 +00001016
Steve Naroff83895f72007-09-16 03:34:24 +00001017 virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
Steve Narofffbd09832007-07-19 01:06:55 +00001018 ExprTy **InitList, unsigned NumInit,
Chris Lattner248388e2008-10-26 23:35:51 +00001019 InitListDesignations &Designators,
Steve Narofffbd09832007-07-19 01:06:55 +00001020 SourceLocation RParenLoc);
1021
Douglas Gregor7d5fc7e2008-11-06 23:29:22 +00001022 virtual ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1023 tok::TokenKind Kind,
Chris Lattner7cee11f2006-11-03 06:42:29 +00001024 ExprTy *LHS,ExprTy *RHS);
Douglas Gregor7d5fc7e2008-11-06 23:29:22 +00001025 ExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1026 unsigned Opc,
1027 Expr *lhs, Expr *rhs);
1028
Steve Naroff83895f72007-09-16 03:34:24 +00001029 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner7cee11f2006-11-03 06:42:29 +00001030 /// in the case of a the GNU conditional expr extension.
Steve Naroff83895f72007-09-16 03:34:24 +00001031 virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +00001032 SourceLocation ColonLoc,
1033 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
Chris Lattner29375652006-12-04 18:06:35 +00001034
Steve Naroff66356bd2007-09-16 14:56:35 +00001035 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
1036 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattnereefa10e2007-05-28 06:56:27 +00001037 IdentifierInfo *LabelII);
1038
Steve Naroff66356bd2007-09-16 14:56:35 +00001039 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner366727f2007-07-24 16:58:17 +00001040 SourceLocation RPLoc); // "({..})"
Chris Lattnerf17bd422007-08-30 17:45:32 +00001041
1042 /// __builtin_offsetof(type, a.b[123][456].c)
Douglas Gregor55297ac2008-12-23 00:26:44 +00001043 virtual ExprResult ActOnBuiltinOffsetOf(Scope *S,
1044 SourceLocation BuiltinLoc,
Chris Lattnerf17bd422007-08-30 17:45:32 +00001045 SourceLocation TypeLoc, TypeTy *Arg1,
1046 OffsetOfComponent *CompPtr,
1047 unsigned NumComponents,
1048 SourceLocation RParenLoc);
1049
Steve Naroff78864672007-08-01 22:05:33 +00001050 // __builtin_types_compatible_p(type1, type2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001051 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +00001052 TypeTy *arg1, TypeTy *arg2,
1053 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +00001054
1055 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff66356bd2007-09-16 14:56:35 +00001056 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff9efdabc2007-08-03 21:21:27 +00001057 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
1058 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +00001059
Nate Begeman1e36a852008-01-17 17:46:27 +00001060 // __builtin_overload(...)
1061 virtual ExprResult ActOnOverloadExpr(ExprTy **Args, unsigned NumArgs,
1062 SourceLocation *CommaLocs,
1063 SourceLocation BuiltinLoc,
1064 SourceLocation RParenLoc);
Nate Begeman0a6192c2008-03-07 20:04:22 +00001065
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001066 // __builtin_va_arg(expr, type)
1067 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1068 ExprTy *expr, TypeTy *type,
1069 SourceLocation RPLoc);
Steve Naroffc540d662008-09-03 18:15:37 +00001070
Douglas Gregor3be4b122008-11-29 04:51:27 +00001071 // __null
1072 virtual ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
1073
Steve Naroffc540d662008-09-03 18:15:37 +00001074 //===------------------------- "Block" Extension ------------------------===//
1075
1076 /// ActOnBlockStart - This callback is invoked when a block literal is
1077 /// started.
Steve Naroff1d95e5a2008-10-10 01:28:17 +00001078 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
1079
1080 /// ActOnBlockArguments - This callback allows processing of block arguments.
1081 /// If there are no arguments, this is still invoked.
1082 virtual void ActOnBlockArguments(Declarator &ParamInfo);
Steve Naroffc540d662008-09-03 18:15:37 +00001083
1084 /// ActOnBlockError - If there is an error parsing a block, this callback
1085 /// is invoked to pop the information about the block from the action impl.
1086 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
1087
1088 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1089 /// literal was successfully completed. ^(int x){...}
1090 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
1091 Scope *CurScope);
1092
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +00001093 // Act on C++ namespaces
1094 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1095 IdentifierInfo *Ident,
1096 SourceLocation LBrace);
1097 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
1098
Douglas Gregord7c4d982008-12-30 03:27:21 +00001099 virtual DeclTy *ActOnUsingDirective(Scope *CurScope,
1100 SourceLocation UsingLoc,
1101 SourceLocation NamespcLoc,
1102 const CXXScopeSpec &SS,
1103 SourceLocation IdentLoc,
1104 IdentifierInfo *NamespcName,
1105 AttributeList *AttrList);
1106
Argyrios Kyrtzidis9a1191c2008-10-06 17:10:33 +00001107 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1108 /// ActOnDeclarator, when a C++ direct initializer is present.
1109 /// e.g: "int x(1);"
1110 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
1111 SourceLocation LParenLoc,
1112 ExprTy **Exprs, unsigned NumExprs,
1113 SourceLocation *CommaLocs,
1114 SourceLocation RParenLoc);
1115
Douglas Gregor6f543152008-11-05 15:29:30 +00001116 /// InitializationKind - Represents which kind of C++ initialization
1117 /// [dcl.init] a routine is to perform.
1118 enum InitializationKind {
1119 IK_Direct, ///< Direct initialization
1120 IK_Copy, ///< Copy initialization
1121 IK_Default ///< Default initialization
1122 };
1123
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001124 CXXConstructorDecl *
Douglas Gregor6f543152008-11-05 15:29:30 +00001125 PerformInitializationByConstructor(QualType ClassType,
1126 Expr **Args, unsigned NumArgs,
1127 SourceLocation Loc, SourceRange Range,
Chris Lattnerf3d3fae2008-11-24 05:29:24 +00001128 DeclarationName InitEntity,
Douglas Gregor6f543152008-11-05 15:29:30 +00001129 InitializationKind Kind);
Douglas Gregorc28b57d2008-11-03 20:45:27 +00001130
Douglas Gregore200adc2008-10-27 19:41:14 +00001131 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
1132 virtual ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
1133 SourceLocation LAngleBracketLoc, TypeTy *Ty,
1134 SourceLocation RAngleBracketLoc,
1135 SourceLocation LParenLoc, ExprTy *E,
1136 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +00001137
Sebastian Redlc4704762008-11-11 11:37:55 +00001138 /// ActOnCXXTypeidOfType - Parse typeid( type-id ).
1139 virtual ExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1140 SourceLocation LParenLoc, bool isType,
1141 void *TyOrExpr, SourceLocation RParenLoc);
1142
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001143 //// ActOnCXXThis - Parse 'this' pointer.
1144 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
1145
Steve Naroff66356bd2007-09-16 14:56:35 +00001146 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
1147 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +00001148 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +00001149
Chris Lattnerb7e656b2008-02-26 00:51:44 +00001150 //// ActOnCXXThrow - Parse throw expressions.
1151 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
1152 ExprTy *expr);
1153
Argyrios Kyrtzidis857fcc22008-08-22 15:38:55 +00001154 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1155 /// Can be interpreted either as function-style casting ("int(x)")
1156 /// or class type construction ("ClassType(x,y,z)")
1157 /// or creation of a value-initialized type ("int()").
1158 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1159 TypeTy *TypeRep,
1160 SourceLocation LParenLoc,
1161 ExprTy **Exprs,
1162 unsigned NumExprs,
1163 SourceLocation *CommaLocs,
1164 SourceLocation RParenLoc);
1165
Sebastian Redlbd150f42008-11-21 19:14:01 +00001166 /// ActOnCXXNew - Parsed a C++ 'new' expression.
1167 virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1168 SourceLocation PlacementLParen,
1169 ExprTy **PlacementArgs, unsigned NumPlaceArgs,
1170 SourceLocation PlacementRParen,
Sebastian Redl351bb782008-12-02 14:43:59 +00001171 bool ParenTypeId, Declarator &D,
Sebastian Redlbd150f42008-11-21 19:14:01 +00001172 SourceLocation ConstructorLParen,
1173 ExprTy **ConstructorArgs, unsigned NumConsArgs,
1174 SourceLocation ConstructorRParen);
Sebastian Redl351bb782008-12-02 14:43:59 +00001175 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redlfaf68082008-12-03 20:26:15 +00001176 bool FindAllocationFunctions(SourceLocation StartLoc, bool UseGlobal,
1177 QualType AllocType, bool IsArray,
1178 Expr **PlaceArgs, unsigned NumPlaceArgs,
1179 FunctionDecl *&OperatorNew,
1180 FunctionDecl *&OperatorDelete);
Sebastian Redl33a31012008-12-04 22:20:51 +00001181 bool FindAllocationOverload(SourceLocation StartLoc, DeclarationName Name,
1182 Expr** Args, unsigned NumArgs, DeclContext *Ctx,
1183 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlfaf68082008-12-03 20:26:15 +00001184 void DeclareGlobalNewDelete();
1185 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1186 QualType Argument);
Sebastian Redlbd150f42008-11-21 19:14:01 +00001187
1188 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
1189 virtual ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
1190 bool ArrayForm, ExprTy *Operand);
1191
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00001192 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1193 /// C++ if/switch/while/for statement.
1194 /// e.g: "if (int x = f()) {...}"
1195 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
1196 SourceLocation StartLoc,
1197 Declarator &D,
1198 SourceLocation EqualLoc,
1199 ExprTy *AssignExprVal);
1200
Sebastian Redlbaad4e72009-01-05 20:52:13 +00001201 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1202 /// pseudo-functions.
1203 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1204 SourceLocation KWLoc,
1205 SourceLocation LParen,
1206 TypeTy *Ty,
1207 SourceLocation RParen);
1208
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001209 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1210 /// global scope ('::').
1211 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1212 SourceLocation CCLoc);
1213
1214 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1215 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1216 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1217 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1218 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1219 /// Returns a CXXScopeTy* object representing the C++ scope.
1220 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1221 const CXXScopeSpec &SS,
1222 SourceLocation IdLoc,
1223 SourceLocation CCLoc,
Douglas Gregorae2fbad2008-11-17 20:34:05 +00001224 IdentifierInfo &II);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001225
1226 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1227 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1228 /// After this method is called, according to [C++ 3.4.3p3], names should be
1229 /// looked up in the declarator-id's scope, until the declarator is parsed and
1230 /// ActOnCXXExitDeclaratorScope is called.
1231 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1232 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1233
1234 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1235 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1236 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1237 /// Used to indicate that names should revert to being looked up in the
1238 /// defining scope.
Douglas Gregor29e174c2008-12-16 00:38:16 +00001239 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argyrios Kyrtzidis16ac9be2008-11-08 17:17:31 +00001240
Anders Carlsson76f4a902007-08-21 17:43:55 +00001241 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnere002fbe2007-12-12 01:04:12 +00001242 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1243 ExprTy **Strings,
1244 unsigned NumStrings);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001245 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner37390be2007-10-16 22:51:17 +00001246 SourceLocation EncodeLoc,
Anders Carlssonc5a81eb2007-08-22 15:14:15 +00001247 SourceLocation LParenLoc,
1248 TypeTy *Ty,
1249 SourceLocation RParenLoc);
1250
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001251 // ParseObjCSelectorExpression - Build selector expression for @selector
1252 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1253 SourceLocation AtLoc,
Fariborz Jahanian6bd1d612007-10-16 23:21:02 +00001254 SourceLocation SelLoc,
Fariborz Jahanian4bef4622007-10-16 20:40:23 +00001255 SourceLocation LParenLoc,
1256 SourceLocation RParenLoc);
1257
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +00001258 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1259 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1260 SourceLocation AtLoc,
1261 SourceLocation ProtoLoc,
1262 SourceLocation LParenLoc,
1263 SourceLocation RParenLoc);
Douglas Gregor556877c2008-04-13 21:30:24 +00001264
1265 //===--------------------------------------------------------------------===//
Douglas Gregor07665a62009-01-05 19:45:36 +00001266 // C++ Declarations
1267 //
1268 virtual DeclTy *ActOnStartLinkageSpecification(Scope *S,
1269 SourceLocation ExternLoc,
1270 SourceLocation LangLoc,
1271 const char *Lang,
1272 unsigned StrSize,
1273 SourceLocation LBraceLoc);
1274 virtual DeclTy *ActOnFinishLinkageSpecification(Scope *S,
1275 DeclTy *LinkageSpec,
1276 SourceLocation RBraceLoc);
1277
1278
1279 //===--------------------------------------------------------------------===//
Douglas Gregor556877c2008-04-13 21:30:24 +00001280 // C++ Classes
1281 //
Argyrios Kyrtzidis32a03792008-11-08 16:45:02 +00001282 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1283 const CXXScopeSpec *SS);
Douglas Gregor61956c42008-10-31 09:07:45 +00001284
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001285 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1286 Declarator &D, ExprTy *BitfieldWidth,
1287 ExprTy *Init, DeclTy *LastInGroup);
1288
Douglas Gregore8381c02008-11-05 04:29:56 +00001289 virtual MemInitResult ActOnMemInitializer(DeclTy *ConstructorD,
1290 Scope *S,
1291 IdentifierInfo *MemberOrBase,
1292 SourceLocation IdLoc,
1293 SourceLocation LParenLoc,
1294 ExprTy **Args, unsigned NumArgs,
1295 SourceLocation *CommaLocs,
1296 SourceLocation RParenLoc);
1297
Douglas Gregor05379422008-11-03 17:51:48 +00001298 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1299
Argyrios Kyrtzidised983422008-07-01 10:37:29 +00001300 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
1301 DeclTy *TagDecl,
1302 SourceLocation LBrac,
1303 SourceLocation RBrac);
1304
Douglas Gregor4d87df52008-12-16 21:30:33 +00001305 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1306 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclTy *Param);
1307 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, DeclTy *Method);
1308
Douglas Gregor831c93f2008-11-05 20:51:48 +00001309 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1310 FunctionDecl::StorageClass& SC);
Douglas Gregor4d87df52008-12-16 21:30:33 +00001311 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor831c93f2008-11-05 20:51:48 +00001312 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1313 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001314 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1315 FunctionDecl::StorageClass& SC);
Douglas Gregordbc5daf2008-11-07 20:08:42 +00001316 DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregor61956c42008-10-31 09:07:45 +00001317
Douglas Gregor5c407d92008-10-23 00:40:37 +00001318 //===--------------------------------------------------------------------===//
1319 // C++ Derived Classes
1320 //
1321
1322 /// ActOnBaseSpecifier - Parsed a base specifier
1323 virtual BaseResult ActOnBaseSpecifier(DeclTy *classdecl,
1324 SourceRange SpecifierRange,
1325 bool Virtual, AccessSpecifier Access,
1326 TypeTy *basetype, SourceLocation BaseLoc);
1327
1328 virtual void ActOnBaseSpecifiers(DeclTy *ClassDecl, BaseTy **Bases,
1329 unsigned NumBases);
1330
1331 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001332 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor960b5bc2009-01-15 00:26:24 +00001333 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1334 BasePaths &Paths);
Douglas Gregorcea4e7432008-10-24 16:17:19 +00001335 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1336 SourceLocation Loc, SourceRange Range);
Douglas Gregor556877c2008-04-13 21:30:24 +00001337
Douglas Gregor11d0c4c2008-11-06 22:13:31 +00001338 //===--------------------------------------------------------------------===//
1339 // C++ Overloaded Operators [C++ 13.5]
1340 //
1341
1342 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1343
Douglas Gregor5101c242008-12-05 18:15:24 +00001344 //===--------------------------------------------------------------------===//
1345 // C++ Templates [C++ 14]
1346 //
Douglas Gregor55ad91f2008-12-18 19:37:40 +00001347 virtual DeclTy *isTemplateName(IdentifierInfo &II, Scope *S,
1348 const CXXScopeSpec *SS = 0);
Douglas Gregor5101c242008-12-05 18:15:24 +00001349 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
1350 virtual DeclTy *ActOnTypeParameter(Scope *S, bool Typename,
1351 SourceLocation KeyLoc,
1352 IdentifierInfo *ParamName,
Douglas Gregorb9bd8a92008-12-24 02:52:09 +00001353 SourceLocation ParamNameLoc,
1354 unsigned Depth, unsigned Position);
1355 virtual DeclTy *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
1356 unsigned Depth,
1357 unsigned Position);
1358 virtual TemplateParamsTy *
1359 ActOnTemplateParameterList(unsigned Depth,
1360 SourceLocation ExportLoc,
1361 SourceLocation TemplateLoc,
1362 SourceLocation LAngleLoc,
1363 DeclTy **Params, unsigned NumParams,
1364 SourceLocation RAngleLoc);
1365
Steve Naroff09bf8152007-09-06 21:24:23 +00001366 // Objective-C declarations.
Chris Lattnerdf59f5a2008-07-26 04:13:19 +00001367 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
1368 IdentifierInfo *ClassName,
1369 SourceLocation ClassLoc,
1370 IdentifierInfo *SuperName,
1371 SourceLocation SuperLoc,
1372 DeclTy * const *ProtoRefs,
1373 unsigned NumProtoRefs,
1374 SourceLocation EndProtoLoc,
1375 AttributeList *AttrList);
Fariborz Jahanian49c64252007-10-11 23:42:27 +00001376
1377 virtual DeclTy *ActOnCompatiblityAlias(
1378 SourceLocation AtCompatibilityAliasLoc,
1379 IdentifierInfo *AliasName, SourceLocation AliasLocation,
1380 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff09bf8152007-09-06 21:24:23 +00001381
Steve Naroff93eb5f12007-10-10 17:32:04 +00001382 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001383 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001384 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner3bbae002008-07-26 04:03:38 +00001385 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar26e2ab42008-09-26 04:48:09 +00001386 SourceLocation EndProtoLoc,
1387 AttributeList *AttrList);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +00001388
Chris Lattnerb1f3c942008-07-26 04:07:02 +00001389 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
1390 IdentifierInfo *ClassName,
1391 SourceLocation ClassLoc,
1392 IdentifierInfo *CategoryName,
1393 SourceLocation CategoryLoc,
1394 DeclTy * const *ProtoRefs,
1395 unsigned NumProtoRefs,
1396 SourceLocation EndProtoLoc);
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +00001397
Steve Naroff93eb5f12007-10-10 17:32:04 +00001398 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman7dd8e722008-02-20 22:57:40 +00001399 SourceLocation AtClassImplLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +00001400 IdentifierInfo *ClassName, SourceLocation ClassLoc,
1401 IdentifierInfo *SuperClassname,
1402 SourceLocation SuperClassLoc);
1403
Steve Naroff93eb5f12007-10-10 17:32:04 +00001404 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +00001405 SourceLocation AtCatImplLoc,
1406 IdentifierInfo *ClassName,
1407 SourceLocation ClassLoc,
1408 IdentifierInfo *CatName,
1409 SourceLocation CatLoc);
1410
Steve Naroff93eb5f12007-10-10 17:32:04 +00001411 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +00001412 IdentifierInfo **IdentList,
1413 unsigned NumElts);
Fariborz Jahanian876e27d2007-09-21 15:40:54 +00001414
Steve Naroff93eb5f12007-10-10 17:32:04 +00001415 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001416 const IdentifierLocPair *IdentList,
Fariborz Jahanian1470e932008-12-17 01:07:27 +00001417 unsigned NumElts,
1418 AttributeList *attrList);
Fariborz Jahanianea7a98d2007-10-05 21:01:53 +00001419
Chris Lattner3bbae002008-07-26 04:03:38 +00001420 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001421 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian70e8f102007-10-11 00:55:41 +00001422 unsigned NumProtocols,
Chris Lattnerd7352d62008-07-21 22:17:28 +00001423 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001424
Daniel Dunbare8a06e62008-09-23 21:53:23 +00001425 /// Ensure attributes are consistent with type.
1426 /// \param [in, out] Attributes The attributes to check; they will
1427 /// be modified to be consistent with \arg PropertyTy.
1428 void CheckObjCPropertyAttributes(QualType PropertyTy,
1429 SourceLocation Loc,
1430 unsigned &Attributes);
Steve Naroff35c62ae2009-01-08 17:28:14 +00001431 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001432 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
1433 ObjCPropertyDecl *SuperProperty,
Chris Lattner86d7d912008-11-24 03:54:41 +00001434 const IdentifierInfo *Name);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +00001435 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian0a070ff2008-04-24 19:58:34 +00001436
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001437 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001438 DeclTy *MergeProtocols);
1439
Fariborz Jahaniand2c2ad52008-12-06 23:03:39 +00001440 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +00001441 ObjCProtocolDecl *PDecl);
1442
Steve Naroffcac26f42007-11-11 17:19:15 +00001443 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
1444 DeclTy **allMethods = 0, unsigned allNum = 0,
1445 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahanian2a4dd312007-09-26 18:27:25 +00001446
Fariborz Jahanian0152a1a2008-04-14 23:36:35 +00001447 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001448 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian09367d62008-05-06 18:09:04 +00001449 Selector GetterSel, Selector SetterSel,
Fariborz Jahanianf8ef9f32008-11-26 20:01:34 +00001450 DeclTy *ClassCategory, bool *OverridingProperty,
Fariborz Jahanian8d916862008-05-05 18:51:55 +00001451 tok::ObjCKeywordKind MethodImplKind);
1452
Fariborz Jahanianffe97a32008-04-18 00:19:30 +00001453 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
1454 SourceLocation PropertyLoc,
1455 bool ImplKind, DeclTy *ClassImplDecl,
1456 IdentifierInfo *PropertyId,
1457 IdentifierInfo *PropertyIvar);
1458
Steve Naroff161a92b2007-10-26 20:53:56 +00001459 virtual DeclTy *ActOnMethodDeclaration(
1460 SourceLocation BeginLoc, // location of the + or -.
1461 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanianb5605172007-11-09 19:52:12 +00001462 tok::TokenKind MethodType,
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001463 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian7a9c4742007-10-31 23:53:01 +00001464 Selector Sel,
Steve Narofff73590d2007-09-27 14:38:14 +00001465 // optional arguments. The number of types/arguments is obtained
1466 // from the Sel.getNumArgs().
Ted Kremenek1b0ea822008-01-07 19:49:32 +00001467 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Fariborz Jahaniane84858c2009-01-09 00:38:19 +00001468 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroffd8ea1ac2007-11-15 12:35:21 +00001469 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
1470 bool isVariadic = false);
Steve Naroff077c83b2007-10-16 23:12:48 +00001471
Steve Narofff73590d2007-09-27 14:38:14 +00001472 // ActOnClassMessage - used for both unary and keyword messages.
1473 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001474 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001475 virtual ExprResult ActOnClassMessage(
Fariborz Jahaniand98a7342007-11-12 20:13:27 +00001476 Scope *S,
Steve Naroff80175062007-09-28 22:22:11 +00001477 IdentifierInfo *receivingClassName, Selector Sel,
Steve Naroff9e4ac112008-11-19 15:54:23 +00001478 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001479 ExprTy **ArgExprs, unsigned NumArgs);
Steve Narofff73590d2007-09-27 14:38:14 +00001480
1481 // ActOnInstanceMessage - used for both unary and keyword messages.
1482 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001483 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +00001484 virtual ExprResult ActOnInstanceMessage(
Steve Naroff80175062007-09-28 22:22:11 +00001485 ExprTy *receiver, Selector Sel,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +00001486 SourceLocation lbrac, SourceLocation rbrac,
1487 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar54603742008-10-14 05:35:18 +00001488
1489 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
1490 virtual void ActOnPragmaPack(PragmaPackKind Kind,
1491 IdentifierInfo *Name,
1492 ExprTy *Alignment,
1493 SourceLocation PragmaLoc,
1494 SourceLocation LParenLoc,
1495 SourceLocation RParenLoc);
1496
Chris Lattnera65e1f32008-01-16 19:17:22 +00001497 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
1498 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregora11693b2008-11-12 17:17:38 +00001499 /// If isLvalue, the result of the cast is an lvalue.
1500 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnera65e1f32008-01-16 19:17:22 +00001501
Steve Naroff71b59a92007-06-04 22:22:31 +00001502 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner08464942007-12-28 05:29:59 +00001503 // functions and arrays to their respective pointers (C99 6.3.2.1).
1504 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3e113402008-05-27 03:33:27 +00001505
Steve Naroff31090012007-07-16 21:54:35 +00001506 // DefaultFunctionArrayConversion - converts functions and arrays
1507 // to their respective pointers (C99 6.3.2.1).
1508 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001509
Steve Naroff0b661582007-08-28 23:30:39 +00001510 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
1511 // do not have a prototype. Integer promotions are performed on each
1512 // argument, and arguments that have type float are promoted to double.
Chris Lattner08464942007-12-28 05:29:59 +00001513 void DefaultArgumentPromotion(Expr *&Expr);
Steve Naroff0b661582007-08-28 23:30:39 +00001514
Steve Naroff71b59a92007-06-04 22:22:31 +00001515 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
1516 // operands and then handles various conversions that are common to binary
1517 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
1518 // routine returns the first non-arithmetic type found. The client is
1519 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001520 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
1521 bool isCompAssign = false);
Chris Lattner940cfeb2008-01-04 18:22:42 +00001522
Douglas Gregora11693b2008-11-12 17:17:38 +00001523 /// UsualArithmeticConversionsType - handles the various conversions
1524 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
1525 /// and returns the result type of that conversion.
1526 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
1527
1528
Chris Lattner940cfeb2008-01-04 18:22:42 +00001529 /// AssignConvertType - All of the 'assignment' semantic checks return this
1530 /// enum to indicate whether the assignment was allowed. These checks are
1531 /// done for simple assignments, as well as initialization, return from
1532 /// function, argument passing, etc. The query is phrased in terms of a
1533 /// source and destination type.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001534 enum AssignConvertType {
Chris Lattner940cfeb2008-01-04 18:22:42 +00001535 /// Compatible - the types are compatible according to the standard.
Steve Naroff17f76e02007-05-03 21:03:48 +00001536 Compatible,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001537
1538 /// PointerToInt - The assignment converts a pointer to an int, which we
1539 /// accept as an extension.
1540 PointerToInt,
1541
1542 /// IntToPointer - The assignment converts an int to a pointer, which we
1543 /// accept as an extension.
1544 IntToPointer,
1545
1546 /// FunctionVoidPointer - The assignment is between a function pointer and
1547 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner0a788432008-01-03 22:56:36 +00001548 FunctionVoidPointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001549
1550 /// IncompatiblePointer - The assignment is between two pointers types that
1551 /// are not compatible, but we accept them as an extension.
Steve Naroff1f4d7272007-05-11 04:00:31 +00001552 IncompatiblePointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +00001553
1554 /// CompatiblePointerDiscardsQualifiers - The assignment discards
1555 /// c/v/r qualifiers, which we accept as an extension.
1556 CompatiblePointerDiscardsQualifiers,
Steve Naroff081c7422008-09-04 15:10:53 +00001557
Steve Naroff991e99d2008-09-04 15:31:07 +00001558 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff081c7422008-09-04 15:10:53 +00001559 /// pointer. We disallow this.
1560 IntToBlockPointer,
1561
Steve Naroff991e99d2008-09-04 15:31:07 +00001562 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff081c7422008-09-04 15:10:53 +00001563 /// pointers types that are not compatible.
1564 IncompatibleBlockPointer,
1565
Steve Naroff8afa9892008-10-14 22:18:38 +00001566 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
1567 /// id type and something else (that is incompatible with it). For example,
1568 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
1569 IncompatibleObjCQualifiedId,
1570
Chris Lattner940cfeb2008-01-04 18:22:42 +00001571 /// Incompatible - We reject this conversion outright, it is invalid to
1572 /// represent it in the AST.
1573 Incompatible
Steve Naroff17f76e02007-05-03 21:03:48 +00001574 };
Chris Lattner9bad62c2008-01-04 18:04:52 +00001575
1576 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
1577 /// assignment conversion type specified by ConvTy. This returns true if the
1578 /// conversion was invalid or false if the conversion was accepted.
1579 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
1580 SourceLocation Loc,
1581 QualType DstType, QualType SrcType,
1582 Expr *SrcExpr, const char *Flavor);
1583
1584 /// CheckAssignmentConstraints - Perform type checking for assignment,
1585 /// argument passing, variable initialization, and function return values.
1586 /// This routine is only used by the following two methods. C99 6.5.16.
1587 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001588
Steve Naroff83895f72007-09-16 03:34:24 +00001589 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff66356bd2007-09-16 14:56:35 +00001590 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001591 // this routine performs the default function/array converions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001592 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
1593 Expr *&rExpr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001594 // CheckCompoundAssignmentConstraints - Type check without performing any
1595 // conversions. For compound assignments, the "Check...Operands" methods
1596 // perform the necessary conversions.
Chris Lattner9bad62c2008-01-04 18:04:52 +00001597 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
1598 QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +00001599
Steve Naroff98cf3e92007-06-06 18:38:38 +00001600 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner9bad62c2008-01-04 18:04:52 +00001601 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
1602 QualType rhsType);
Steve Naroff081c7422008-09-04 15:10:53 +00001603
1604 // Helper function for CheckAssignmentConstraints involving two
1605 // blcok pointer types.
1606 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
1607 QualType rhsType);
Douglas Gregoraa1e21d2008-09-12 00:47:35 +00001608
1609 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001610
Douglas Gregor47d3f272008-12-19 17:40:08 +00001611 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00001612 const char *Flavor, bool AllowExplicit = false);
1613 bool PerformImplicitConversion(Expr *&From, QualType ToType,
1614 const ImplicitConversionSequence& ICS,
Douglas Gregor47d3f272008-12-19 17:40:08 +00001615 const char *Flavor);
Douglas Gregor39c16d42008-10-24 04:54:22 +00001616 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor47d3f272008-12-19 17:40:08 +00001617 const StandardConversionSequence& SCS,
1618 const char *Flavor);
Steve Naroff9eb24652007-05-02 21:58:15 +00001619
Steve Naroff8eeeb132007-05-08 21:09:37 +00001620 /// the following "Check" methods will return a valid/converted QualType
1621 /// or a null QualType (indicating an error diagnostic was issued).
1622
Steve Naroff83895f72007-09-16 03:34:24 +00001623 /// type checking binary operators (subroutines of ActOnBinOp).
Chris Lattner5c11c412007-12-12 05:47:28 +00001624 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001625 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001626 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001627 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001628 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001629 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001630 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001631 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001632 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001633 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001634 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnerb620c342007-08-26 01:18:55 +00001635 inline QualType CheckCompareOperands( // C99 6.5.8/9
1636 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001637 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroffbe4c4d12007-08-24 19:07:16 +00001638 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001639 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +00001640 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +00001641 // CheckAssignmentOperands is used for both simple and compound assignment.
1642 // For simple assignment, pass both expressions and a null converted type.
1643 // For compound assignment, pass both expressions and the converted type.
1644 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0c1c7ed2007-08-24 22:33:52 +00001645 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +00001646 inline QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner326f7572008-11-18 01:30:42 +00001647 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +00001648 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +00001649 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begeman191a6b12008-07-14 18:02:46 +00001650
1651 /// type checking for vector binary operators.
1652 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
1653 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
1654 SourceLocation l, bool isRel);
Steve Naroff95af0132007-03-30 23:47:58 +00001655
Steve Naroff83895f72007-09-16 03:34:24 +00001656 /// type checking unary operators (subroutines of ActOnUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +00001657 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redle10c2c32008-12-20 09:35:34 +00001658 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
1659 bool isInc);
Steve Naroff71ce2e02007-05-18 22:53:50 +00001660 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
1661 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner74ed76b2007-08-24 21:41:10 +00001662 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Narofff8fd09e2007-07-27 22:15:19 +00001663
1664 /// type checking primary expressions.
Nate Begemance4d7fc2008-04-18 23:10:10 +00001665 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Narofff8fd09e2007-07-27 22:15:19 +00001666 IdentifierInfo &Comp, SourceLocation CmpLoc);
1667
Steve Naroff2fea1392007-09-02 02:04:30 +00001668 /// type checking declaration initializers (C99 6.7.8)
Steve Narofff8ecff22008-05-01 22:18:59 +00001669 friend class InitListChecker;
Douglas Gregor6f543152008-11-05 15:29:30 +00001670 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor5fb53972009-01-14 15:45:31 +00001671 SourceLocation InitLoc,DeclarationName InitEntity,
1672 bool DirectInit);
1673 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType,
1674 bool DirectInit);
Steve Naroff98f72032008-01-10 22:15:12 +00001675 bool CheckForConstantInitializer(Expr *e, QualType t);
Eli Friedmand5a55bd2008-05-20 13:48:25 +00001676 bool CheckArithmeticConstantExpression(const Expr* e);
1677 bool CheckAddressConstantExpression(const Expr* e);
1678 bool CheckAddressConstantExpressionLValue(const Expr* e);
Steve Naroffc6db58a2008-10-27 11:34:16 +00001679 void InitializerElementNotConstant(const Expr *e);
Steve Naroff91f78082007-12-10 22:44:33 +00001680
Steve Naroffaf2a0222008-01-22 00:55:40 +00001681 StringLiteral *IsStringLiteralInit(Expr *Init, QualType DeclType);
1682 bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT);
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00001683
Douglas Gregor8e1cf602008-10-29 00:13:59 +00001684 // type checking C++ declaration initializers (C++ [dcl.init]).
1685
1686 /// ReferenceCompareResult - Expresses the result of comparing two
1687 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
1688 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
1689 enum ReferenceCompareResult {
1690 /// Ref_Incompatible - The two types are incompatible, so direct
1691 /// reference binding is not possible.
1692 Ref_Incompatible = 0,
1693 /// Ref_Related - The two types are reference-related, which means
1694 /// that their unqualified forms (T1 and T2) are either the same
1695 /// or T1 is a base class of T2.
1696 Ref_Related,
1697 /// Ref_Compatible_With_Added_Qualification - The two types are
1698 /// reference-compatible with added qualification, meaning that
1699 /// they are reference-compatible and the qualifiers on T1 (cv1)
1700 /// are greater than the qualifiers on T2 (cv2).
1701 Ref_Compatible_With_Added_Qualification,
1702 /// Ref_Compatible - The two types are reference-compatible and
1703 /// have equivalent qualifiers (cv1 == cv2).
1704 Ref_Compatible
1705 };
1706
Douglas Gregor786ab212008-10-29 02:00:59 +00001707 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
1708 bool& DerivedToBase);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00001709
1710 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor2fe98832008-11-03 19:09:14 +00001711 ImplicitConversionSequence *ICS = 0,
Douglas Gregor5fb53972009-01-14 15:45:31 +00001712 bool SuppressUserConversions = false,
1713 bool AllowExplicit = false);
Douglas Gregor8e1cf602008-10-29 00:13:59 +00001714
Argyrios Kyrtzidis2ade3902008-08-16 20:27:34 +00001715 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar94834d82008-08-20 03:55:42 +00001716 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffaf2a0222008-01-22 00:55:40 +00001717
Anders Carlsson24c59952007-11-27 07:16:40 +00001718 // CheckVectorCast - check type constraints for vectors.
1719 // Since vectors are an extension, there are no C standard reference for this.
1720 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonde71adf2007-11-27 05:51:55 +00001721 // returns true if the cast is invalid
1722 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
1723
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00001724 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
1725 /// \param Method - May be null.
1726 /// \param [out] ReturnType - The return type of the send.
1727 /// \return true iff there were any incompatible types.
Daniel Dunbarce05c8e2008-09-11 00:50:25 +00001728 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattnere4b95692008-11-24 03:33:13 +00001729 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbaraa9326c2008-09-11 00:01:56 +00001730 SourceLocation lbrac, SourceLocation rbrac,
1731 QualType &ReturnType);
Argyrios Kyrtzidis7620ee42008-09-10 02:17:11 +00001732
1733 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
1734 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff077c83b2007-10-16 23:12:48 +00001735
Chris Lattnerfc1c44a2007-08-23 05:46:52 +00001736 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
1737 /// the specified width and sign. If an overflow occurs, detect it and emit
1738 /// the specified diagnostic.
1739 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
1740 unsigned NewWidth, bool NewSign,
1741 SourceLocation Loc, unsigned DiagID);
1742
Chris Lattner2a3569b2008-04-07 05:30:13 +00001743 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
1744 bool ForCompare);
1745
Anders Carlssona6b508a2008-11-04 16:57:32 +00001746 /// Checks that the Objective-C declaration is declared in the global scope.
1747 /// Emits an error and marks the declaration as invalid if it's not declared
1748 /// in the global scope.
1749 bool CheckObjCDeclScope(Decl *D);
1750
Anders Carlsson7e13ab82007-10-15 20:28:48 +00001751 void InitBuiltinVaListType();
Eli Friedman149614b2008-06-03 21:01:11 +00001752
Anders Carlssone54e8a12008-11-30 19:50:32 +00001753 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
1754 /// and reports the appropriate diagnostics. Returns false on success.
1755 /// Can optionally return the value of the expression.
Anders Carlsson5df391e2008-12-06 20:33:04 +00001756 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson1dbffc62008-12-01 02:17:22 +00001757
Anders Carlsson5df391e2008-12-06 20:33:04 +00001758 /// VerifyBitField - verifies that a bit field expression is an ICE and has
1759 /// the correct width, and that the field type is valid.
1760 /// Returns false on success.
1761 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
1762 QualType FieldTy, const Expr *BitWidth);
1763
Chris Lattnerb87b1b32007-08-10 20:18:51 +00001764 //===--------------------------------------------------------------------===//
1765 // Extra semantic analysis beyond the C type system
Chris Lattner08464942007-12-28 05:29:59 +00001766private:
Eli Friedmana1b4ed82008-05-14 19:38:39 +00001767 Action::ExprResult CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
Chris Lattner08464942007-12-28 05:29:59 +00001768 bool CheckBuiltinCFStringArgument(Expr* Arg);
1769 bool SemaBuiltinVAStart(CallExpr *TheCall);
1770 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedmanf8353032008-05-20 08:23:37 +00001771 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Eli Friedmana1b4ed82008-05-14 19:38:39 +00001772 Action::ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbarb7257262008-07-21 22:59:13 +00001773 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbarb0d34c82008-09-03 21:13:56 +00001774 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek6dfeb552009-01-12 23:09:09 +00001775 bool SemaCheckStringLiteral(Expr *E, CallExpr *TheCall, bool HasVAListArg,
1776 unsigned format_idx);
1777 void CheckPrintfString(StringLiteral *FExpr, Expr *OrigFormatExpr,
1778 CallExpr *TheCall, bool HasVAListArg,
1779 unsigned format_idx);
Chris Lattner08464942007-12-28 05:29:59 +00001780 void CheckPrintfArguments(CallExpr *TheCall,
1781 bool HasVAListArg, unsigned format_idx);
Ted Kremenekcff94fa2007-08-17 16:46:58 +00001782 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
1783 SourceLocation ReturnLoc);
Ted Kremenek43fb8b02007-11-25 00:58:00 +00001784 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner7cee11f2006-11-03 06:42:29 +00001785};
1786
Steve Narofff8ecff22008-05-01 22:18:59 +00001787class InitListChecker {
1788 Sema *SemaRef;
1789 bool hadError;
1790
1791 void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
1792 unsigned &Index);
Steve Naroff125d73d2008-05-06 00:23:44 +00001793 void CheckExplicitInitList(InitListExpr *IList, QualType &T,
Steve Narofff8ecff22008-05-01 22:18:59 +00001794 unsigned &Index);
1795
Eli Friedman23a9e312008-05-19 19:16:24 +00001796 void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
1797 unsigned &Index);
1798 void CheckSubElementType(InitListExpr *IList, QualType ElemType,
1799 unsigned &Index);
Steve Narofff8ecff22008-05-01 22:18:59 +00001800 // FIXME: Does DeclType need to be a reference type?
1801 void CheckScalarType(InitListExpr *IList, QualType &DeclType,
1802 unsigned &Index);
1803 void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index);
1804 void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
Eli Friedman23a9e312008-05-19 19:16:24 +00001805 unsigned &Index);
Steve Narofff8ecff22008-05-01 22:18:59 +00001806 void CheckArrayType(InitListExpr *IList, QualType &DeclType, unsigned &Index);
1807
1808 int numArrayElements(QualType DeclType);
1809 int numStructUnionElements(QualType DeclType);
1810public:
1811 InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
1812 bool HadError() { return hadError; }
1813};
1814
Steve Naroffc540d662008-09-03 18:15:37 +00001815/// BlockSemaInfo - When a block is being parsed, this contains information
1816/// about the block. It is pointed to from Sema::CurBlock.
1817struct BlockSemaInfo {
1818 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroffc540d662008-09-03 18:15:37 +00001819 bool hasPrototype;
1820 bool isVariadic;
1821
Steve Naroff44078b92008-10-08 18:44:00 +00001822 BlockDecl *TheDecl;
1823
Steve Naroffc540d662008-09-03 18:15:37 +00001824 /// TheScope - This is the scope for the block itself, which contains
1825 /// arguments etc.
1826 Scope *TheScope;
1827
1828 /// ReturnType - This will get set to block result type, by looking at
1829 /// return types, if any, in the block body.
1830 Type *ReturnType;
1831
1832 /// PrevBlockInfo - If this is nested inside another block, this points
1833 /// to the outer block.
1834 BlockSemaInfo *PrevBlockInfo;
1835};
1836
Chris Lattner7cee11f2006-11-03 06:42:29 +00001837
1838} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +00001839
1840#endif