blob: 5a53374033d26b201109559d85c45e653cb4f346 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
17
Chris Lattner2a1e2ed2008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argiris Kirtzidis38f16712008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Douglas Gregord2baafd2008-10-21 16:13:35 +000020#include "SemaOverload.h"
Douglas Gregor78d70132009-01-14 22:20:51 +000021#include "clang/AST/DeclBase.h"
Chris Lattner4b009652007-07-25 00:24:17 +000022#include "clang/Parse/Action.h"
Chris Lattner545f39e2009-01-29 05:15:15 +000023#include "clang/Sema/SemaDiagnostic.h"
Chris Lattner4b009652007-07-25 00:24:17 +000024#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian67907bd2007-10-05 18:00:57 +000025#include "llvm/ADT/DenseSet.h"
Chris Lattnera7a191c2007-10-07 01:13:46 +000026#include "llvm/ADT/SmallPtrSet.h"
Argiris Kirtzidis38f16712008-07-01 10:37:29 +000027#include "llvm/ADT/OwningPtr.h"
Steve Narofffe56a632009-03-05 15:22:01 +000028#include "clang/AST/DeclObjC.h"
Douglas Gregorb9ef0552009-01-16 00:38:09 +000029#include <string>
Douglas Gregorbb461502008-10-24 04:54:22 +000030#include <vector>
Chris Lattner4b009652007-07-25 00:24:17 +000031
Chris Lattner3429a812007-08-23 05:46:52 +000032namespace llvm {
33 class APSInt;
34}
35
Chris Lattner4b009652007-07-25 00:24:17 +000036namespace clang {
37 class ASTContext;
Chris Lattnera8c2d592008-02-06 00:46:58 +000038 class ASTConsumer;
Chris Lattner4b009652007-07-25 00:24:17 +000039 class Preprocessor;
40 class Decl;
Chris Lattnerf3874bc2008-04-06 04:47:34 +000041 class DeclContext;
Daniel Dunbar8d03cbe2008-08-11 03:27:53 +000042 class DeclSpec;
Steve Naroffe57c21a2008-04-01 23:04:06 +000043 class NamedDecl;
Sebastian Redl91f9b0a2008-12-13 16:23:55 +000044 class Stmt;
Chris Lattner4b009652007-07-25 00:24:17 +000045 class Expr;
Steve Naroff9091f3f2007-09-02 15:34:30 +000046 class InitListExpr;
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +000047 class DesignatedInitExpr;
Chris Lattner83bd5eb2007-12-28 05:29:59 +000048 class CallExpr;
Douglas Gregor566782a2009-01-06 05:10:23 +000049 class DeclRefExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000050 class VarDecl;
51 class ParmVarDecl;
52 class TypedefDecl;
53 class FunctionDecl;
54 class QualType;
Sebastian Redl9cc59542009-03-07 12:16:37 +000055 class LangOptions;
Chris Lattner4b009652007-07-25 00:24:17 +000056 class Token;
57 class IntegerLiteral;
Steve Naroff0d4e6ad2008-01-22 00:55:40 +000058 class StringLiteral;
Chris Lattner4b009652007-07-25 00:24:17 +000059 class ArrayType;
60 class LabelStmt;
61 class SwitchStmt;
Nate Begemanaf6ed502008-04-18 23:10:10 +000062 class ExtVectorType;
Steve Naroff82113e32007-07-29 16:33:31 +000063 class TypedefDecl;
Douglas Gregor279272e2009-02-04 19:02:06 +000064 class TemplateDecl;
Douglas Gregorad964b32009-02-17 01:05:43 +000065 class TemplateArgument;
Douglas Gregord406b032009-02-06 22:42:48 +000066 class TemplateParameterList;
Douglas Gregor35d81bb2009-02-09 23:23:08 +000067 class TemplateTemplateParmDecl;
Douglas Gregor0d93f692009-02-25 22:02:03 +000068 class ClassTemplateDecl;
Ted Kremenek42730c52008-01-07 19:49:32 +000069 class ObjCInterfaceDecl;
Steve Naroffe57c21a2008-04-01 23:04:06 +000070 class ObjCCompatibleAliasDecl;
Ted Kremenek42730c52008-01-07 19:49:32 +000071 class ObjCProtocolDecl;
Chris Lattner7cc13bf2009-03-01 00:56:52 +000072 class ObjCImplDecl;
Ted Kremenek42730c52008-01-07 19:49:32 +000073 class ObjCImplementationDecl;
74 class ObjCCategoryImplDecl;
75 class ObjCCategoryDecl;
76 class ObjCIvarDecl;
77 class ObjCMethodDecl;
Fariborz Jahanianed986602008-05-01 00:03:38 +000078 class ObjCPropertyDecl;
Steve Naroffab63fd62009-01-08 17:28:14 +000079 class ObjCContainerDecl;
Douglas Gregorbb461502008-10-24 04:54:22 +000080 class BasePaths;
Sebastian Redl9cc59542009-03-07 12:16:37 +000081 struct MemberLookupCriteria;
Steve Naroff82113e32007-07-29 16:33:31 +000082
Chris Lattner2616d8c2009-04-18 20:01:55 +000083/// BlockSemaInfo - When a block is being parsed, this contains information
84/// about the block. It is pointed to from Sema::CurBlock.
85struct BlockSemaInfo {
86 llvm::SmallVector<ParmVarDecl*, 8> Params;
87 bool hasPrototype;
88 bool isVariadic;
89 bool hasBlockDeclRefExprs;
90
91 BlockDecl *TheDecl;
92
93 /// TheScope - This is the scope for the block itself, which contains
94 /// arguments etc.
95 Scope *TheScope;
96
97 /// ReturnType - This will get set to block result type, by looking at
98 /// return types, if any, in the block body.
99 Type *ReturnType;
100
101 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
102 /// it (which acts like the label decl in some ways). Forward referenced
103 /// labels have a LabelStmt created for them with a null location & SubStmt.
104 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
105
Chris Lattneree5a1a22009-04-18 20:10:59 +0000106 /// SwitchStack - This is the current set of active switch statements in the
107 /// block.
108 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
109
Chris Lattnere7765e12009-04-19 05:28:12 +0000110 /// SavedFunctionNeedsScopeChecking - This is the value of
111 /// CurFunctionNeedsScopeChecking at the point when the block started.
112 bool SavedFunctionNeedsScopeChecking;
113
Chris Lattner2616d8c2009-04-18 20:01:55 +0000114 /// PrevBlockInfo - If this is nested inside another block, this points
115 /// to the outer block.
116 BlockSemaInfo *PrevBlockInfo;
117};
118
Chris Lattner4b009652007-07-25 00:24:17 +0000119/// Sema - This implements semantic analysis and AST building for C.
120class Sema : public Action {
Chris Lattner767678f2009-02-17 00:58:30 +0000121 Sema(const Sema&); // DO NOT IMPLEMENT
122 void operator=(const Sema&); // DO NOT IMPLEMENT
Chris Lattnerf6690152008-06-29 00:28:59 +0000123public:
Chris Lattner6d89a8a2009-01-22 19:21:44 +0000124 const LangOptions &LangOpts;
Chris Lattner4b009652007-07-25 00:24:17 +0000125 Preprocessor &PP;
Chris Lattner4b009652007-07-25 00:24:17 +0000126 ASTContext &Context;
Chris Lattnera8c2d592008-02-06 00:46:58 +0000127 ASTConsumer &Consumer;
Chris Lattnerf9ea6a42008-11-22 08:28:49 +0000128 Diagnostic &Diags;
129 SourceManager &SourceMgr;
Steve Naroffdd2e26c2007-11-12 13:56:41 +0000130
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000131 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerf3874bc2008-04-06 04:47:34 +0000132 DeclContext *CurContext;
Chris Lattnereee57c02008-04-04 06:12:32 +0000133
Argiris Kirtzidis054a2632008-11-08 17:17:31 +0000134 /// PreDeclaratorDC - Keeps the declaration context before switching to the
135 /// context of a declarator's nested-name-specifier.
136 DeclContext *PreDeclaratorDC;
137
Steve Naroff52a81c02008-09-03 18:15:37 +0000138 /// CurBlock - If inside of a block definition, this contains a pointer to
139 /// the active block object that represents it.
140 BlockSemaInfo *CurBlock;
141
Daniel Dunbar81c7d472008-10-14 05:35:18 +0000142 /// PackContext - Manages the stack for #pragma pack. An alignment
143 /// of 0 indicates default alignment.
Chris Lattnera8699562009-02-17 01:09:29 +0000144 void *PackContext; // Really a "PragmaPackStack*"
Daniel Dunbar81c7d472008-10-14 05:35:18 +0000145
Chris Lattner2616d8c2009-04-18 20:01:55 +0000146 /// FunctionLabelMap - This is a mapping from label identifiers to the
147 /// LabelStmt for it (which acts like the label decl in some ways). Forward
148 /// referenced labels have a LabelStmt created for them with a null location &
149 /// SubStmt.
150 ///
151 /// Note that this should always be accessed through getLabelMap() in order
152 /// to handle blocks properly.
153 llvm::DenseMap<IdentifierInfo*, LabelStmt*> FunctionLabelMap;
Steve Naroffb88d81c2009-03-13 15:38:40 +0000154
Chris Lattneree5a1a22009-04-18 20:10:59 +0000155 /// FunctionSwitchStack - This is the current set of active switch statements
156 /// in the top level function. Clients should always use getSwitchStack() to
157 /// handle the case when they are in a block.
158 llvm::SmallVector<SwitchStmt*, 8> FunctionSwitchStack;
Steve Naroff82113e32007-07-29 16:33:31 +0000159
Chris Lattnerc92920c2009-04-19 05:21:20 +0000160 /// CurFunctionNeedsScopeChecking - This is set to true when a function or
161 /// ObjC method body contains a VLA or an ObjC try block, which introduce
162 /// scopes that need to be checked for goto conditions. If a function does
163 /// not contain this, then it need not have the jump checker run on it.
164 bool CurFunctionNeedsScopeChecking;
165
Nate Begemanaf6ed502008-04-18 23:10:10 +0000166 /// ExtVectorDecls - This is a list all the extended vector types. This allows
167 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroff82113e32007-07-29 16:33:31 +0000168 /// This is only necessary for issuing pretty diagnostics.
Nate Begemanaf6ed502008-04-18 23:10:10 +0000169 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattner2e64c072007-08-10 20:18:51 +0000170
Steve Naroff4b9846d2008-09-28 14:55:53 +0000171 /// ObjCImplementations - Keep track of all class @implementations
172 /// so we can emit errors on duplicates.
Ted Kremenek42730c52008-01-07 19:49:32 +0000173 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattnera7a191c2007-10-07 01:13:46 +0000174
Steve Naroff4b9846d2008-09-28 14:55:53 +0000175 /// ObjCCategoryImpls - Maintain a list of category implementations so
176 /// we can check for duplicates and find local method declarations.
177 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
178
Ted Kremenek42730c52008-01-07 19:49:32 +0000179 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanianac142de2007-10-09 18:03:53 +0000180 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner042e6e82007-10-09 18:18:24 +0000181 /// find the declarations when needed.
Ted Kremenek42730c52008-01-07 19:49:32 +0000182 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff15208162008-04-02 18:30:49 +0000183
184 /// ObjCInterfaceDecls - Keep track of all class declarations declared
185 /// with @interface, so that we can emit errors on duplicates and
186 /// find the declarations when needed.
187 typedef llvm::DenseMap<const IdentifierInfo*,
188 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
189 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
190
Steve Naroffe57c21a2008-04-01 23:04:06 +0000191 /// ObjCAliasDecls - Keep track of all class declarations declared
192 /// with @compatibility_alias, so that we can emit errors on duplicates and
193 /// find the declarations when needed. This construct is ancient and will
194 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroff64334ea2008-04-02 00:39:51 +0000195 typedef llvm::DenseMap<const IdentifierInfo*,
196 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroffe57c21a2008-04-01 23:04:06 +0000197 ObjCAliasTy ObjCAliasDecls;
Steve Naroff15208162008-04-02 18:30:49 +0000198
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000199 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
200 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
201
Anders Carlssone1299b32009-03-22 20:18:17 +0000202 typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy;
203
204 /// PureVirtualClassDiagSet - a set of class declarations which we have
205 /// emitted a list of pure virtual functions. Used to prevent emitting the
206 /// same list more than once.
207 llvm::OwningPtr<RecordDeclSetTy> PureVirtualClassDiagSet;
208
Douglas Gregore6b5d1d2009-03-02 00:19:53 +0000209 /// \brief A mapping from external names to the most recent
210 /// locally-scoped external declaration with that name.
211 ///
212 /// This map contains external declarations introduced in local
213 /// scoped, e.g.,
214 ///
215 /// \code
216 /// void f() {
217 /// void foo(int, int);
218 /// }
219 /// \endcode
220 ///
221 /// Here, the name "foo" will be associated with the declaration on
222 /// "foo" within f. This name is not visible outside of
223 /// "f". However, we still find it in two cases:
224 ///
225 /// - If we are declaring another external with the name "foo", we
226 /// can find "foo" as a previous declaration, so that the types
227 /// of this external declaration can be checked for
228 /// compatibility.
229 ///
230 /// - If we would implicitly declare "foo" (e.g., due to a call to
231 /// "foo" in C when no prototype or definition is visible), then
232 /// we find this declaration of "foo" and complain that it is
233 /// not visible.
234 llvm::DenseMap<DeclarationName, NamedDecl *> LocallyScopedExternalDecls;
235
Douglas Gregor9cdb4a12009-04-21 17:11:58 +0000236 /// \brief The set of tentative declarations seen so far in this
237 /// translation unit for which no definition has been seen.
238 ///
239 /// The tentative declarations are indexed by the name of the
240 /// declaration, and only the most recent tentative declaration for
241 /// a given variable will be recorded here.
242 llvm::DenseMap<DeclarationName, VarDecl *> TentativeDefinitions;
243
Chris Lattner2a1e2ed2008-04-11 07:00:53 +0000244 IdentifierResolver IdResolver;
245
Steve Naroff415c1832007-10-10 17:32:04 +0000246 /// Translation Unit Scope - useful to Objective-C actions that need
247 /// to lookup file scope declarations in the "ordinary" C decl namespace.
248 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroff9637a9b2007-10-09 22:01:59 +0000249 Scope *TUScope;
Sebastian Redlb93b49c2008-11-11 11:37:55 +0000250
251 /// The C++ "std" namespace, where the standard library resides. Cached here
252 /// by GetStdNamespace
253 NamespaceDecl *StdNamespace;
Sebastian Redlb5ee8742008-12-03 20:26:15 +0000254
255 /// A flag to remember whether the implicit forms of operator new and delete
256 /// have been declared.
257 bool GlobalNewDeleteDeclared;
Douglas Gregore0d5c562009-04-14 16:27:31 +0000258
259 /// \brief Whether the code handled by Sema should be considered a
260 /// complete translation unit or not.
261 ///
262 /// When true (which is generally the case), Sema will perform
263 /// end-of-translation-unit semantic tasks (such as creating
264 /// initializers for tentative definitions in C) once parsing has
265 /// completed. This flag will be false when building PCH files,
266 /// since a PCH file is by definition not a complete translation
267 /// unit.
268 bool CompleteTranslationUnit;
269
Steve Naroff8255b042007-10-14 00:58:41 +0000270 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek42730c52008-01-07 19:49:32 +0000271 struct ObjCMethodList {
272 ObjCMethodDecl *Method;
273 ObjCMethodList *Next;
Steve Naroff8255b042007-10-14 00:58:41 +0000274
Ted Kremenek42730c52008-01-07 19:49:32 +0000275 ObjCMethodList() {
Steve Naroff8255b042007-10-14 00:58:41 +0000276 Method = 0;
277 Next = 0;
278 }
Ted Kremenek42730c52008-01-07 19:49:32 +0000279 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff8255b042007-10-14 00:58:41 +0000280 Method = M;
281 Next = C;
282 }
283 };
284 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
285 /// messages to "id". We need to maintain a list, since selectors can have
286 /// differing signatures across classes. In Cocoa, this happens to be
287 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremenek42730c52008-01-07 19:49:32 +0000288 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
289 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Steve Naroffff6c8022009-03-04 15:11:40 +0000290
291 /// Private Helper predicate to check for 'self'.
292 bool isSelfExpr(Expr *RExpr);
Chris Lattner4b009652007-07-25 00:24:17 +0000293public:
Douglas Gregore0d5c562009-04-14 16:27:31 +0000294 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
295 bool CompleteTranslationUnit = true);
Chris Lattnera8699562009-02-17 01:09:29 +0000296 ~Sema() {
297 if (PackContext) FreePackedContext();
298 }
Chris Lattner4b009652007-07-25 00:24:17 +0000299
Chris Lattner6d89a8a2009-01-22 19:21:44 +0000300 const LangOptions &getLangOptions() const { return LangOpts; }
Chris Lattnerf9ea6a42008-11-22 08:28:49 +0000301 Diagnostic &getDiagnostics() const { return Diags; }
302 SourceManager &getSourceManager() const { return SourceMgr; }
303
Douglas Gregor46970ed2009-03-20 22:48:49 +0000304 /// \brief Helper class that creates diagnostics with optional
305 /// template instantiation stacks.
306 ///
307 /// This class provides a wrapper around the basic DiagnosticBuilder
308 /// class that emits diagnostics. SemaDiagnosticBuilder is
309 /// responsible for emitting the diagnostic (as DiagnosticBuilder
310 /// does) and, if the diagnostic comes from inside a template
311 /// instantiation, printing the template instantiation stack as
312 /// well.
313 class SemaDiagnosticBuilder : public DiagnosticBuilder {
314 Sema &SemaRef;
315 unsigned DiagID;
316
317 public:
318 SemaDiagnosticBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID)
319 : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) { }
320
321 ~SemaDiagnosticBuilder();
322 };
323
324 /// \brief Emit a diagnostic.
325 SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
Douglas Gregorfee85d62009-03-10 18:03:33 +0000326 DiagnosticBuilder DB = Diags.Report(FullSourceLoc(Loc, SourceMgr), DiagID);
Douglas Gregor46970ed2009-03-20 22:48:49 +0000327 return SemaDiagnosticBuilder(DB, *this, DiagID);
Chris Lattnerf9ea6a42008-11-22 08:28:49 +0000328 }
Chris Lattner4b009652007-07-25 00:24:17 +0000329
Chris Lattnerb26b7ad2007-08-31 04:53:24 +0000330 virtual void DeleteExpr(ExprTy *E);
331 virtual void DeleteStmt(StmtTy *S);
332
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000333 OwningExprResult Owned(Expr* E) { return OwningExprResult(*this, E); }
Sebastian Redl8b769972009-01-19 00:08:26 +0000334 OwningExprResult Owned(ExprResult R) {
Douglas Gregor10a18fc2009-01-26 22:44:13 +0000335 if (R.isInvalid())
Steve Naroff27959652009-01-21 22:32:33 +0000336 return ExprError();
Douglas Gregor10a18fc2009-01-26 22:44:13 +0000337 return OwningExprResult(*this, R.get());
Sebastian Redl8b769972009-01-19 00:08:26 +0000338 }
Sebastian Redl91f9b0a2008-12-13 16:23:55 +0000339 OwningStmtResult Owned(Stmt* S) { return OwningStmtResult(*this, S); }
340
Chris Lattnerc1aea812008-08-23 03:19:52 +0000341 virtual void ActOnEndOfTranslationUnit();
Sebastian Redl5457c5e2009-01-19 22:31:54 +0000342
Chris Lattner2616d8c2009-04-18 20:01:55 +0000343 /// getLabelMap() - Return the current label map. If we're in a block, we
344 /// return it.
345 llvm::DenseMap<IdentifierInfo*, LabelStmt*> &getLabelMap() {
346 return CurBlock ? CurBlock->LabelMap : FunctionLabelMap;
347 }
348
Chris Lattneree5a1a22009-04-18 20:10:59 +0000349 /// getSwitchStack - This is returns the switch stack for the current block or
350 /// function.
351 llvm::SmallVector<SwitchStmt*,8> &getSwitchStack() {
352 return CurBlock ? CurBlock->SwitchStack : FunctionSwitchStack;
353 }
354
Chris Lattner4b009652007-07-25 00:24:17 +0000355 //===--------------------------------------------------------------------===//
356 // Type Analysis / Processing: SemaType.cpp.
357 //
Douglas Gregora6897272009-03-23 23:06:20 +0000358 QualType adjustParameterType(QualType T);
Chris Lattner8a447af2009-04-22 05:27:59 +0000359 QualType ConvertDeclSpecToType(const DeclSpec &DS, SourceLocation DeclLoc);
Chris Lattner65a57042008-06-29 00:50:08 +0000360 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000361 QualType BuildPointerType(QualType T, unsigned Quals,
362 SourceLocation Loc, DeclarationName Entity);
Sebastian Redlce6fff02009-03-16 23:22:08 +0000363 QualType BuildReferenceType(QualType T, bool LValueRef, unsigned Quals,
Douglas Gregorf57dcd02009-02-28 00:25:32 +0000364 SourceLocation Loc, DeclarationName Entity);
365 QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
366 Expr *ArraySize, unsigned Quals,
367 SourceLocation Loc, DeclarationName Entity);
Douglas Gregorc0139ca2009-02-28 01:04:19 +0000368 QualType BuildFunctionType(QualType T,
369 QualType *ParamTypes, unsigned NumParamTypes,
370 bool Variadic, unsigned Quals,
371 SourceLocation Loc, DeclarationName Entity);
Sebastian Redl66df3ef2008-12-02 14:43:59 +0000372 QualType GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip = 0);
Douglas Gregor6704b312008-11-17 22:58:34 +0000373 DeclarationName GetNameForDeclarator(Declarator &D);
374
Chris Lattner5261d0c2009-03-28 19:18:32 +0000375 QualType ObjCGetTypeForMethodDefinition(DeclPtrTy D);
Fariborz Jahaniandfb1c372007-11-08 23:49:49 +0000376
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000377 bool UnwrapSimilarPointerTypes(QualType& T1, QualType& T2);
378
Sebastian Redl66df3ef2008-12-02 14:43:59 +0000379 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Sebastian Redlf831eeb2008-11-08 13:00:26 +0000380
Douglas Gregorc84d8932009-03-09 16:13:40 +0000381 bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned diag,
Douglas Gregor46fe06e2009-01-19 19:26:10 +0000382 SourceRange Range1 = SourceRange(),
383 SourceRange Range2 = SourceRange(),
384 QualType PrintType = QualType());
385
Douglas Gregor8c795a12009-03-19 00:39:20 +0000386 QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T);
387
Chris Lattner4b009652007-07-25 00:24:17 +0000388 //===--------------------------------------------------------------------===//
389 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
390 //
Chris Lattnerd042d0f2009-03-05 01:25:28 +0000391
392 /// getDeclName - Return a pretty name for the specified decl if possible, or
393 /// an empty string if not. This is used for pretty crash reporting.
Chris Lattner5261d0c2009-03-28 19:18:32 +0000394 virtual std::string getDeclName(DeclPtrTy D);
Chris Lattnerd042d0f2009-03-05 01:25:28 +0000395
Chris Lattnera17991f2009-03-29 16:50:03 +0000396 DeclGroupPtrTy ConvertDeclToDeclGroup(DeclPtrTy Ptr);
397
Douglas Gregora60c62e2009-02-09 15:09:02 +0000398 virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
Douglas Gregor1075a162009-02-04 17:00:24 +0000399 Scope *S, const CXXScopeSpec *SS);
Chris Lattner197b4342009-04-12 21:49:30 +0000400 virtual DeclSpec::TST isTagName(IdentifierInfo &II, Scope *S);
401
Chris Lattnera17991f2009-03-29 16:50:03 +0000402 virtual DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D) {
403 return ActOnDeclarator(S, D, false);
Douglas Gregorc5cbc242008-12-15 23:53:10 +0000404 }
Chris Lattnera17991f2009-03-29 16:50:03 +0000405 DeclPtrTy ActOnDeclarator(Scope *S, Declarator &D, bool IsFunctionDefinition);
Douglas Gregore6b5d1d2009-03-02 00:19:53 +0000406 void RegisterLocallyScopedExternCDecl(NamedDecl *ND, NamedDecl *PrevDecl,
407 Scope *S);
Eli Friedmanf834eaf2009-04-07 19:37:57 +0000408 void DiagnoseFunctionSpecifiers(Declarator& D);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000409 NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Chris Lattnera17991f2009-03-29 16:50:03 +0000410 QualType R,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000411 Decl* PrevDecl, bool& InvalidDecl,
412 bool &Redeclaration);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000413 NamedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Chris Lattnera17991f2009-03-29 16:50:03 +0000414 QualType R,
Douglas Gregor92c47912009-02-24 19:23:27 +0000415 NamedDecl* PrevDecl, bool& InvalidDecl,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000416 bool &Redeclaration);
Douglas Gregorafb094a2009-03-25 23:32:15 +0000417 bool CheckVariableDeclaration(VarDecl *NewVD, NamedDecl *PrevDecl,
418 bool &Redeclaration);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +0000419 NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
Chris Lattnera17991f2009-03-29 16:50:03 +0000420 QualType R, NamedDecl* PrevDecl,
Douglas Gregoraf682022009-02-24 01:23:02 +0000421 bool IsFunctionDefinition,
Douglas Gregor083c23e2009-02-16 17:45:42 +0000422 bool& InvalidDecl, bool &Redeclaration);
Douglas Gregora6897272009-03-23 23:06:20 +0000423 bool CheckFunctionDeclaration(FunctionDecl *NewFD, NamedDecl *&PrevDecl,
424 bool &Redeclaration,
425 bool &OverloadableAttrRequired);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000426 virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D);
427 virtual void ActOnParamDefaultArgument(DeclPtrTy param,
Chris Lattner3e254fb2008-04-08 04:40:51 +0000428 SourceLocation EqualLoc,
Sebastian Redl76bb8ec2009-03-15 17:47:39 +0000429 ExprArg defarg);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000430 virtual void ActOnParamUnparsedDefaultArgument(DeclPtrTy param,
Douglas Gregor62ae25a2008-12-24 00:01:03 +0000431 SourceLocation EqualLoc);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000432 virtual void ActOnParamDefaultArgumentError(DeclPtrTy param);
433 virtual void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init);
434 void AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit);
435 void ActOnUninitializedDecl(DeclPtrTy dcl);
436 virtual void SetDeclDeleted(DeclPtrTy dcl, SourceLocation DelLoc);
Chris Lattnera17991f2009-03-29 16:50:03 +0000437 virtual DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, DeclPtrTy *Group,
438 unsigned NumDecls);
Douglas Gregor3faaa812009-04-01 23:51:29 +0000439 virtual void ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
440 SourceLocation LocAfterDecls);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000441 virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, Declarator &D);
442 virtual DeclPtrTy ActOnStartOfFunctionDef(Scope *S, DeclPtrTy D);
443 virtual void ActOnStartOfObjCMethodDef(Scope *S, DeclPtrTy D);
Sebastian Redl5457c5e2009-01-19 22:31:54 +0000444
Chris Lattner5261d0c2009-03-28 19:18:32 +0000445 virtual DeclPtrTy ActOnFinishFunctionBody(DeclPtrTy Decl, StmtArg Body);
Chris Lattner76b831a2009-04-19 04:46:21 +0000446 void DiagnoseInvalidJumps(Stmt *Body);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000447 virtual DeclPtrTy ActOnFileScopeAsmDecl(SourceLocation Loc, ExprArg expr);
Anders Carlsson4f7f4412008-02-08 00:33:21 +0000448
Steve Naroff9637a9b2007-10-09 22:01:59 +0000449 /// Scope actions.
450 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
451 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner4b009652007-07-25 00:24:17 +0000452
453 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
454 /// no declarator (e.g. "struct foo;") is parsed.
Chris Lattner5261d0c2009-03-28 19:18:32 +0000455 virtual DeclPtrTy ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
Chris Lattner4b009652007-07-25 00:24:17 +0000456
Douglas Gregor723d3332009-01-07 00:43:41 +0000457 bool InjectAnonymousStructOrUnionMembers(Scope *S, DeclContext *Owner,
458 RecordDecl *AnonRecord);
Chris Lattner5261d0c2009-03-28 19:18:32 +0000459 virtual DeclPtrTy BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
460 RecordDecl *Record);
Douglas Gregor723d3332009-01-07 00:43:41 +0000461
Chris Lattner5261d0c2009-03-28 19:18:32 +0000462 virtual DeclPtrTy ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
463 SourceLocation KWLoc, const CXXScopeSpec &SS,
464 IdentifierInfo *Name, SourceLocation NameLoc,
465 AttributeList *Attr, AccessSpecifier AS);
Ted Kremenek46a837c2008-09-05 17:16:31 +0000466
Chris Lattner5261d0c2009-03-28 19:18:32 +0000467 virtual void ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart,
Chris Lattnerf7df4d12008-08-23 02:00:52 +0000468 IdentifierInfo *ClassName,
Chris Lattner5261d0c2009-03-28 19:18:32 +0000469 llvm::SmallVectorImpl<DeclPtrTy> &Decls);
470 virtual DeclPtrTy ActOnField(Scope *S, DeclPtrTy TagD,
471 SourceLocation DeclStart,
472 Declarator &D, ExprTy *BitfieldWidth);
Chris Lattner9cffefc2009-03-05 22:45:59 +0000473
474 FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart,
Douglas Gregor2f0ecef2009-03-11 20:50:30 +0000475 Declarator &D, Expr *BitfieldWidth,
476 AccessSpecifier AS);
Chris Lattner9cffefc2009-03-05 22:45:59 +0000477
Douglas Gregor0e518af2009-03-11 18:59:21 +0000478 FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T,
479 RecordDecl *Record, SourceLocation Loc,
480 bool Mutable, Expr *BitfieldWidth,
Douglas Gregor2f0ecef2009-03-11 20:50:30 +0000481 AccessSpecifier AS, NamedDecl *PrevDecl,
Douglas Gregor0e518af2009-03-11 18:59:21 +0000482 Declarator *D = 0);
Fariborz Jahanian751c6172008-04-10 23:32:45 +0000483
Chris Lattner5261d0c2009-03-28 19:18:32 +0000484 virtual DeclPtrTy ActOnIvar(Scope *S, SourceLocation DeclStart,
485 Declarator &D, ExprTy *BitfieldWidth,
486 tok::ObjCKeywordKind visibility);
Fariborz Jahanian751c6172008-04-10 23:32:45 +0000487
Steve Naroffffeaa552007-09-14 23:09:53 +0000488 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000489 virtual void ActOnFields(Scope* S,
Chris Lattner5261d0c2009-03-28 19:18:32 +0000490 SourceLocation RecLoc, DeclPtrTy TagDecl,
491 DeclPtrTy *Fields, unsigned NumFields,
Daniel Dunbarf3944442008-10-03 02:03:53 +0000492 SourceLocation LBrac, SourceLocation RBrac,
493 AttributeList *AttrList);
Douglas Gregordb568cf2009-01-08 20:45:30 +0000494
495 /// ActOnTagStartDefinition - Invoked when we have entered the
496 /// scope of a tag's definition (e.g., for an enumeration, class,
497 /// struct, or union).
Chris Lattner5261d0c2009-03-28 19:18:32 +0000498 virtual void ActOnTagStartDefinition(Scope *S, DeclPtrTy TagDecl);
Douglas Gregordb568cf2009-01-08 20:45:30 +0000499
500 /// ActOnTagFinishDefinition - Invoked once we have finished parsing
501 /// the definition of a tag (enumeration, class, struct, or union).
Chris Lattner5261d0c2009-03-28 19:18:32 +0000502 virtual void ActOnTagFinishDefinition(Scope *S, DeclPtrTy TagDecl);
Douglas Gregordb568cf2009-01-08 20:45:30 +0000503
Douglas Gregor3ae974b2009-03-17 19:05:46 +0000504 EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum,
505 EnumConstantDecl *LastEnumConst,
506 SourceLocation IdLoc,
507 IdentifierInfo *Id,
508 ExprArg val);
509
Chris Lattner5261d0c2009-03-28 19:18:32 +0000510 virtual DeclPtrTy ActOnEnumConstant(Scope *S, DeclPtrTy EnumDecl,
511 DeclPtrTy LastEnumConstant,
512 SourceLocation IdLoc, IdentifierInfo *Id,
513 SourceLocation EqualLoc, ExprTy *Val);
514 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclPtrTy EnumDecl,
515 DeclPtrTy *Elements, unsigned NumElements);
Sebastian Redlf831eeb2008-11-08 13:00:26 +0000516
Argiris Kirtzidis054a2632008-11-08 17:17:31 +0000517 DeclContext *getContainingDC(DeclContext *DC);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +0000518
Chris Lattnereee57c02008-04-04 06:12:32 +0000519 /// Set the current declaration context until it gets popped.
Douglas Gregor8acb7272008-12-11 16:49:14 +0000520 void PushDeclContext(Scope *S, DeclContext *DC);
Chris Lattnerf3874bc2008-04-06 04:47:34 +0000521 void PopDeclContext();
Argiris Kirtzidis95256e62008-06-28 06:07:14 +0000522
Chris Lattnere5cb5862008-12-04 23:50:19 +0000523 /// getCurFunctionDecl - If inside of a function body, this returns a pointer
524 /// to the function decl for the function being parsed. If we're currently
525 /// in a 'block', this returns the containing context.
526 FunctionDecl *getCurFunctionDecl();
527
528 /// getCurMethodDecl - If inside of a method body, this returns a pointer to
529 /// the method decl for the method being parsed. If we're currently
530 /// in a 'block', this returns the containing context.
Daniel Dunbar64789f82008-08-11 05:35:13 +0000531 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnereee57c02008-04-04 06:12:32 +0000532
Chris Lattnere5cb5862008-12-04 23:50:19 +0000533 /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method
534 /// or C function we're in, otherwise return null. If we're currently
535 /// in a 'block', this returns the containing context.
536 NamedDecl *getCurFunctionOrMethodDecl();
537
Argiris Kirtzidis951f25b2008-04-12 00:47:19 +0000538 /// Add this decl to the scope shadowed decl chains.
539 void PushOnScopeChains(NamedDecl *D, Scope *S);
540
Argiris Kirtzidis90842b62008-09-09 21:18:04 +0000541 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
542 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
543 /// true if 'D' belongs to the given declaration context.
544 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
Douglas Gregor8acb7272008-12-11 16:49:14 +0000545 return IdResolver.isDeclInScope(D, Ctx, Context, S);
Argiris Kirtzidis90842b62008-09-09 21:18:04 +0000546 }
547
Eli Friedman9c0e6f92009-02-28 05:41:13 +0000548
Chris Lattner9e982502008-02-21 01:07:18 +0000549 /// Subroutines of ActOnDeclarator().
Chris Lattnera17991f2009-03-29 16:50:03 +0000550 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T);
Douglas Gregor083c23e2009-02-16 17:45:42 +0000551 bool MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
552 bool MergeFunctionDecl(FunctionDecl *New, Decl *Old);
Douglas Gregoraf682022009-02-24 01:23:02 +0000553 bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregor083c23e2009-02-16 17:45:42 +0000554 bool MergeVarDecl(VarDecl *New, Decl *Old);
555 bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000556
557 /// C++ Overloading.
558 bool IsOverload(FunctionDecl *New, Decl* OldD,
559 OverloadedFunctionDecl::function_iterator &MatchedDecl);
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000560 ImplicitConversionSequence
561 TryImplicitConversion(Expr* From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000562 bool SuppressUserConversions = false,
Sebastian Redla55834a2009-04-12 17:16:29 +0000563 bool AllowExplicit = false,
564 bool ForceRValue = false);
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000565 bool IsStandardConversion(Expr *From, QualType ToType,
566 StandardConversionSequence& SCS);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000567 bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType);
568 bool IsFloatingPointPromotion(QualType FromType, QualType ToType);
Douglas Gregore819caf2009-02-12 00:15:05 +0000569 bool IsComplexPromotion(QualType FromType, QualType ToType);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000570 bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType,
Douglas Gregor6fd35572008-12-19 17:40:08 +0000571 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregor932778b2008-12-19 19:13:09 +0000572 bool isObjCPointerConversion(QualType FromType, QualType ToType,
573 QualType& ConvertedType, bool &IncompatibleObjC);
Douglas Gregorbb461502008-10-24 04:54:22 +0000574 bool CheckPointerConversion(Expr *From, QualType ToType);
Sebastian Redlba387562009-01-25 19:43:20 +0000575 bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType,
576 QualType &ConvertedType);
577 bool CheckMemberPointerConversion(Expr *From, QualType ToType);
Douglas Gregor6573cfd2008-10-21 23:43:52 +0000578 bool IsQualificationConversion(QualType FromType, QualType ToType);
Douglas Gregorb72e9da2008-10-31 16:23:19 +0000579 bool IsUserDefinedConversion(Expr *From, QualType ToType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000580 UserDefinedConversionSequence& User,
Douglas Gregorb206cc42009-01-30 23:27:23 +0000581 bool AllowConversionFunctions,
Sebastian Redla55834a2009-04-12 17:16:29 +0000582 bool AllowExplicit, bool ForceRValue);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000583
584 ImplicitConversionSequence::CompareKind
585 CompareImplicitConversionSequences(const ImplicitConversionSequence& ICS1,
586 const ImplicitConversionSequence& ICS2);
587
588 ImplicitConversionSequence::CompareKind
589 CompareStandardConversionSequences(const StandardConversionSequence& SCS1,
590 const StandardConversionSequence& SCS2);
591
Douglas Gregorccc0ccc2008-10-22 14:17:15 +0000592 ImplicitConversionSequence::CompareKind
593 CompareQualificationConversions(const StandardConversionSequence& SCS1,
594 const StandardConversionSequence& SCS2);
595
Douglas Gregor14046502008-10-23 00:40:37 +0000596 ImplicitConversionSequence::CompareKind
597 CompareDerivedToBaseConversions(const StandardConversionSequence& SCS1,
598 const StandardConversionSequence& SCS2);
599
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000600 ImplicitConversionSequence
601 TryCopyInitialization(Expr* From, QualType ToType,
Sebastian Redla55834a2009-04-12 17:16:29 +0000602 bool SuppressUserConversions = false,
603 bool ForceRValue = false);
Douglas Gregor81c29152008-10-29 00:13:59 +0000604 bool PerformCopyInitialization(Expr *&From, QualType ToType,
Sebastian Redla55834a2009-04-12 17:16:29 +0000605 const char *Flavor, bool Elidable = false);
Douglas Gregor81c29152008-10-29 00:13:59 +0000606
Douglas Gregor5ed15042008-11-18 23:14:02 +0000607 ImplicitConversionSequence
608 TryObjectArgumentInitialization(Expr *From, CXXMethodDecl *Method);
609 bool PerformObjectArgumentInitialization(Expr *&From, CXXMethodDecl *Method);
610
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000611 ImplicitConversionSequence TryContextuallyConvertToBool(Expr *From);
612 bool PerformContextuallyConvertToBool(Expr *&From);
613
Douglas Gregord2baafd2008-10-21 16:13:35 +0000614 /// OverloadingResult - Capture the result of performing overload
615 /// resolution.
616 enum OverloadingResult {
617 OR_Success, ///< Overload resolution succeeded.
618 OR_No_Viable_Function, ///< No viable function found.
Douglas Gregoraa57e862009-02-18 21:56:37 +0000619 OR_Ambiguous, ///< Ambiguous candidates found.
620 OR_Deleted ///< Overload resoltuion refers to a deleted function.
Douglas Gregord2baafd2008-10-21 16:13:35 +0000621 };
622
Douglas Gregor00fe3f62009-03-13 18:40:31 +0000623 typedef llvm::SmallPtrSet<FunctionDecl *, 16> FunctionSet;
624 typedef llvm::SmallPtrSet<NamespaceDecl *, 16> AssociatedNamespaceSet;
625 typedef llvm::SmallPtrSet<CXXRecordDecl *, 16> AssociatedClassSet;
626
Douglas Gregord2baafd2008-10-21 16:13:35 +0000627 void AddOverloadCandidate(FunctionDecl *Function,
628 Expr **Args, unsigned NumArgs,
Douglas Gregora3b34bb2008-11-03 19:09:14 +0000629 OverloadCandidateSet& CandidateSet,
Sebastian Redla55834a2009-04-12 17:16:29 +0000630 bool SuppressUserConversions = false,
631 bool ForceRValue = false);
Douglas Gregor00fe3f62009-03-13 18:40:31 +0000632 void AddFunctionCandidates(const FunctionSet &Functions,
633 Expr **Args, unsigned NumArgs,
634 OverloadCandidateSet& CandidateSet,
635 bool SuppressUserConversions = false);
Douglas Gregor5ed15042008-11-18 23:14:02 +0000636 void AddMethodCandidate(CXXMethodDecl *Method,
637 Expr *Object, Expr **Args, unsigned NumArgs,
638 OverloadCandidateSet& CandidateSet,
Sebastian Redla55834a2009-04-12 17:16:29 +0000639 bool SuppressUserConversions = false,
640 bool ForceRValue = false);
Douglas Gregor60714f92008-11-07 22:36:19 +0000641 void AddConversionCandidate(CXXConversionDecl *Conversion,
642 Expr *From, QualType ToType,
643 OverloadCandidateSet& CandidateSet);
Douglas Gregor67fdb5b2008-11-19 22:57:39 +0000644 void AddSurrogateCandidate(CXXConversionDecl *Conversion,
Douglas Gregor4fa58902009-02-26 23:50:07 +0000645 const FunctionProtoType *Proto,
Douglas Gregor67fdb5b2008-11-19 22:57:39 +0000646 Expr *Object, Expr **Args, unsigned NumArgs,
647 OverloadCandidateSet& CandidateSet);
Douglas Gregor00fe3f62009-03-13 18:40:31 +0000648 void AddOperatorCandidates(OverloadedOperatorKind Op, Scope *S,
Douglas Gregor48a87322009-02-04 16:44:47 +0000649 SourceLocation OpLoc,
Douglas Gregor5ed15042008-11-18 23:14:02 +0000650 Expr **Args, unsigned NumArgs,
Douglas Gregor48a87322009-02-04 16:44:47 +0000651 OverloadCandidateSet& CandidateSet,
652 SourceRange OpRange = SourceRange());
Douglas Gregor00fe3f62009-03-13 18:40:31 +0000653 void AddMemberOperatorCandidates(OverloadedOperatorKind Op,
654 SourceLocation OpLoc,
655 Expr **Args, unsigned NumArgs,
656 OverloadCandidateSet& CandidateSet,
657 SourceRange OpRange = SourceRange());
Douglas Gregor70d26122008-11-12 17:17:38 +0000658 void AddBuiltinCandidate(QualType ResultTy, QualType *ParamTys,
659 Expr **Args, unsigned NumArgs,
Douglas Gregorab141112009-01-13 00:52:54 +0000660 OverloadCandidateSet& CandidateSet,
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000661 bool IsAssignmentOperator = false,
662 unsigned NumContextualBoolArguments = 0);
Douglas Gregor4f6904d2008-11-19 15:42:04 +0000663 void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
664 Expr **Args, unsigned NumArgs,
665 OverloadCandidateSet& CandidateSet);
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000666 void AddArgumentDependentLookupCandidates(DeclarationName Name,
667 Expr **Args, unsigned NumArgs,
668 OverloadCandidateSet& CandidateSet);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000669 bool isBetterOverloadCandidate(const OverloadCandidate& Cand1,
670 const OverloadCandidate& Cand2);
671 OverloadingResult BestViableFunction(OverloadCandidateSet& CandidateSet,
672 OverloadCandidateSet::iterator& Best);
673 void PrintOverloadCandidates(OverloadCandidateSet& CandidateSet,
674 bool OnlyViable);
675
Douglas Gregor45014fd2008-11-10 20:40:00 +0000676 FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
677 bool Complain);
678 void FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
679
Douglas Gregor4646f9c2009-02-04 15:01:18 +0000680 FunctionDecl *ResolveOverloadedCallFn(Expr *Fn, NamedDecl *Callee,
681 DeclarationName UnqualifiedName,
Douglas Gregorbf4f0582008-11-26 06:01:48 +0000682 SourceLocation LParenLoc,
683 Expr **Args, unsigned NumArgs,
684 SourceLocation *CommaLocs,
Douglas Gregoraa1da4a2009-02-04 00:32:51 +0000685 SourceLocation RParenLoc,
Douglas Gregor4646f9c2009-02-04 15:01:18 +0000686 bool &ArgumentDependentLookup);
Douglas Gregor00fe3f62009-03-13 18:40:31 +0000687
Douglas Gregorc78182d2009-03-13 23:49:33 +0000688 OwningExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc,
689 unsigned Opc,
690 FunctionSet &Functions,
691 ExprArg input);
692
Douglas Gregor00fe3f62009-03-13 18:40:31 +0000693 OwningExprResult CreateOverloadedBinOp(SourceLocation OpLoc,
694 unsigned Opc,
695 FunctionSet &Functions,
696 Expr *LHS, Expr *RHS);
697
Douglas Gregor3257fb52008-12-22 05:46:06 +0000698 ExprResult
699 BuildCallToMemberFunction(Scope *S, Expr *MemExpr,
700 SourceLocation LParenLoc, Expr **Args,
701 unsigned NumArgs, SourceLocation *CommaLocs,
702 SourceLocation RParenLoc);
Douglas Gregor10f3c502008-11-19 21:05:33 +0000703 ExprResult
Douglas Gregora133e262008-12-06 00:22:45 +0000704 BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc,
Douglas Gregor10f3c502008-11-19 21:05:33 +0000705 Expr **Args, unsigned NumArgs,
706 SourceLocation *CommaLocs,
707 SourceLocation RParenLoc);
Douglas Gregord2baafd2008-10-21 16:13:35 +0000708
Douglas Gregorddfd9d52008-12-23 00:26:44 +0000709 ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc,
Douglas Gregor7f3fec52008-11-20 16:27:02 +0000710 SourceLocation MemberLoc,
711 IdentifierInfo &Member);
Douglas Gregor6214d8a2009-01-14 15:45:31 +0000712
Chris Lattner7898bf62009-01-06 07:27:21 +0000713 /// Helpers for dealing with function parameters.
Chris Lattner3e254fb2008-04-08 04:40:51 +0000714 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner3e254fb2008-04-08 04:40:51 +0000715 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor2b9422f2008-05-07 04:49:29 +0000716 void CheckExtraCXXDefaultArguments(Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000717
Douglas Gregor5eca99e2009-01-12 18:45:55 +0000718 Scope *getNonFieldDeclScope(Scope *S);
719
Douglas Gregor78d70132009-01-14 22:20:51 +0000720 /// \name Name lookup
721 ///
722 /// These routines provide name lookup that is used during semantic
723 /// analysis to resolve the various kinds of names (identifiers,
724 /// overloaded operator names, constructor names, etc.) into zero or
725 /// more declarations within a particular scope. The major entry
726 /// points are LookupName, which performs unqualified name lookup,
727 /// and LookupQualifiedName, which performs qualified name lookup.
728 ///
729 /// All name lookup is performed based on some specific criteria,
730 /// which specify what names will be visible to name lookup and how
731 /// far name lookup should work. These criteria are important both
732 /// for capturing language semantics (certain lookups will ignore
733 /// certain names, for example) and for performance, since name
734 /// lookup is often a bottleneck in the compilation of C++. Name
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000735 /// lookup criteria is specified via the LookupCriteria enumeration.
Douglas Gregor78d70132009-01-14 22:20:51 +0000736 ///
737 /// The results of name lookup can vary based on the kind of name
738 /// lookup performed, the current language, and the translation
739 /// unit. In C, for example, name lookup will either return nothing
740 /// (no entity found) or a single declaration. In C++, name lookup
741 /// can additionally refer to a set of overloaded functions or
742 /// result in an ambiguity. All of the possible results of name
743 /// lookup are captured by the LookupResult class, which provides
744 /// the ability to distinguish among them.
745 //@{
Douglas Gregor5ff0ee52008-12-30 03:27:21 +0000746
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000747 /// @brief Describes the kind of name lookup to perform.
748 enum LookupNameKind {
749 /// Ordinary name lookup, which finds ordinary names (functions,
750 /// variables, typedefs, etc.) in C and most kinds of names
751 /// (functions, variables, members, types, etc.) in C++.
752 LookupOrdinaryName = 0,
753 /// Tag name lookup, which finds the names of enums, classes,
754 /// structs, and unions.
755 LookupTagName,
756 /// Member name lookup, which finds the names of
757 /// class/struct/union members.
758 LookupMemberName,
Douglas Gregor48a87322009-02-04 16:44:47 +0000759 // Look up of an operator name (e.g., operator+) for use with
760 // operator overloading. This lookup is similar to ordinary name
761 // lookup, but will ignore any declarations that are class
762 // members.
763 LookupOperatorName,
Douglas Gregor52ae30c2009-01-30 01:04:22 +0000764 /// Look up of a name that precedes the '::' scope resolution
765 /// operator in C++. This lookup completely ignores operator,
766 /// function, and enumerator names (C++ [basic.lookup.qual]p1).
767 LookupNestedNameSpecifierName,
768 /// Look up a namespace name within a C++ using directive or
769 /// namespace alias definition, ignoring non-namespace names (C++
770 /// [basic.lookup.udir]p1).
Douglas Gregor1c52c632009-02-24 20:03:32 +0000771 LookupNamespaceName,
772 // Look up an ordinary name that is going to be redeclared as a
773 // name with linkage. This lookup ignores any declarations that
774 // are outside of the current scope unless they have linkage. See
775 // C99 6.2.2p4-5 and C++ [basic.link]p6.
776 LookupRedeclarationWithLinkage
Douglas Gregor78d70132009-01-14 22:20:51 +0000777 };
778
779 /// @brief Represents the results of name lookup.
780 ///
781 /// An instance of the LookupResult class captures the results of a
782 /// single name lookup, which can return no result (nothing found),
783 /// a single declaration, a set of overloaded functions, or an
784 /// ambiguity. Use the getKind() method to determine which of these
785 /// results occurred for a given lookup.
786 ///
787 /// Any non-ambiguous lookup can be converted into a single
Douglas Gregor09be81b2009-02-04 17:27:36 +0000788 /// (possibly NULL) @c NamedDecl* via a conversion function or the
Douglas Gregor78d70132009-01-14 22:20:51 +0000789 /// getAsDecl() method. This conversion permits the common-case
790 /// usage in C and Objective-C where name lookup will always return
791 /// a single declaration.
Douglas Gregord07474b2009-01-17 01:13:24 +0000792 struct LookupResult {
Douglas Gregor78d70132009-01-14 22:20:51 +0000793 /// The kind of entity that is actually stored within the
794 /// LookupResult object.
Douglas Gregord07474b2009-01-17 01:13:24 +0000795 enum {
Douglas Gregor09be81b2009-02-04 17:27:36 +0000796 /// First is a single declaration (a NamedDecl*), which may be NULL.
Douglas Gregor78d70132009-01-14 22:20:51 +0000797 SingleDecl,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000798
Douglas Gregor7a7be652009-02-03 19:21:40 +0000799 /// First is a single declaration (an OverloadedFunctionDecl*).
800 OverloadedDeclSingleDecl,
801
Douglas Gregor78d70132009-01-14 22:20:51 +0000802 /// [First, Last) is an iterator range represented as opaque
803 /// pointers used to reconstruct IdentifierResolver::iterators.
804 OverloadedDeclFromIdResolver,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000805
Douglas Gregor78d70132009-01-14 22:20:51 +0000806 /// [First, Last) is an iterator range represented as opaque
807 /// pointers used to reconstruct DeclContext::lookup_iterators.
808 OverloadedDeclFromDeclContext,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000809
810 /// First is a pointer to a BasePaths structure, which is owned
811 /// by the LookupResult. Last is non-zero to indicate that the
812 /// ambiguity is caused by two names found in base class
813 /// subobjects of different types.
Douglas Gregor7a7be652009-02-03 19:21:40 +0000814 AmbiguousLookupStoresBasePaths,
815
816 /// [First, Last) is an iterator range represented as opaque
817 /// pointers used to reconstruct new'ed Decl*[] array containing
818 /// found ambiguous decls. LookupResult is owner of this array.
819 AmbiguousLookupStoresDecls
Douglas Gregor78d70132009-01-14 22:20:51 +0000820 } StoredKind;
821
822 /// The first lookup result, whose contents depend on the kind of
Douglas Gregor09be81b2009-02-04 17:27:36 +0000823 /// lookup result. This may be a NamedDecl* (if StoredKind ==
824 /// SingleDecl), OverloadedFunctionDecl* (if StoredKind ==
825 /// OverloadedDeclSingleDecl), the opaque pointer from an
Douglas Gregor78d70132009-01-14 22:20:51 +0000826 /// IdentifierResolver::iterator (if StoredKind ==
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000827 /// OverloadedDeclFromIdResolver), a DeclContext::lookup_iterator
828 /// (if StoredKind == OverloadedDeclFromDeclContext), or a
Douglas Gregor7a7be652009-02-03 19:21:40 +0000829 /// BasePaths pointer (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor78d70132009-01-14 22:20:51 +0000830 mutable uintptr_t First;
831
832 /// The last lookup result, whose contents depend on the kind of
833 /// lookup result. This may be unused (if StoredKind ==
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000834 /// SingleDecl), it may have the same type as First (for
835 /// overloaded function declarations), or is may be used as a
Douglas Gregor7a7be652009-02-03 19:21:40 +0000836 /// Boolean value (if StoredKind == AmbiguousLookupStoresBasePaths).
Douglas Gregor78d70132009-01-14 22:20:51 +0000837 mutable uintptr_t Last;
838
839 /// Context - The context in which we will build any
840 /// OverloadedFunctionDecl nodes needed by the conversion to
841 /// Decl*.
842 ASTContext *Context;
843
Douglas Gregor78d70132009-01-14 22:20:51 +0000844 /// @brief The kind of entity found by name lookup.
845 enum LookupKind {
846 /// @brief No entity found met the criteria.
847 NotFound = 0,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000848
Douglas Gregor78d70132009-01-14 22:20:51 +0000849 /// @brief Name lookup found a single declaration that met the
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000850 /// criteria. getAsDecl will return this declaration.
Douglas Gregor78d70132009-01-14 22:20:51 +0000851 Found,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000852
Douglas Gregor78d70132009-01-14 22:20:51 +0000853 /// @brief Name lookup found a set of overloaded functions that
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000854 /// met the criteria. getAsDecl will turn this set of overloaded
855 /// functions into an OverloadedFunctionDecl.
Douglas Gregor78d70132009-01-14 22:20:51 +0000856 FoundOverloaded,
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000857
858 /// Name lookup results in an ambiguity because multiple
859 /// entities that meet the lookup criteria were found in
860 /// subobjects of different types. For example:
861 /// @code
862 /// struct A { void f(int); }
863 /// struct B { void f(double); }
864 /// struct C : A, B { };
865 /// void test(C c) {
866 /// c.f(0); // error: A::f and B::f come from subobjects of different
867 /// // types. overload resolution is not performed.
868 /// }
869 /// @endcode
870 AmbiguousBaseSubobjectTypes,
871
872 /// Name lookup results in an ambiguity because multiple
873 /// nonstatic entities that meet the lookup criteria were found
874 /// in different subobjects of the same type. For example:
875 /// @code
876 /// struct A { int x; };
877 /// struct B : A { };
878 /// struct C : A { };
879 /// struct D : B, C { };
880 /// int test(D d) {
881 /// return d.x; // error: 'x' is found in two A subobjects (of B and C)
882 /// }
883 /// @endcode
Douglas Gregor7a7be652009-02-03 19:21:40 +0000884 AmbiguousBaseSubobjects,
885
886 /// Name lookup results in an ambiguity because multiple definitions
887 /// of entity that meet the lookup criteria were found in different
888 /// declaration contexts.
889 /// @code
890 /// namespace A {
891 /// int i;
892 /// namespace B { int i; }
893 /// int test() {
894 /// using namespace B;
895 /// return i; // error 'i' is found in namespace A and A::B
896 /// }
897 /// }
898 /// @endcode
899 AmbiguousReference
Douglas Gregor78d70132009-01-14 22:20:51 +0000900 };
901
Douglas Gregor09be81b2009-02-04 17:27:36 +0000902 static LookupResult CreateLookupResult(ASTContext &Context, NamedDecl *D);
Douglas Gregor6beddfe2009-01-15 02:19:31 +0000903
Douglas Gregord07474b2009-01-17 01:13:24 +0000904 static LookupResult CreateLookupResult(ASTContext &Context,
905 IdentifierResolver::iterator F,
906 IdentifierResolver::iterator L);
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000907
Douglas Gregord07474b2009-01-17 01:13:24 +0000908 static LookupResult CreateLookupResult(ASTContext &Context,
909 DeclContext::lookup_iterator F,
910 DeclContext::lookup_iterator L);
Douglas Gregor78d70132009-01-14 22:20:51 +0000911
Douglas Gregord07474b2009-01-17 01:13:24 +0000912 static LookupResult CreateLookupResult(ASTContext &Context, BasePaths *Paths,
913 bool DifferentSubobjectTypes) {
914 LookupResult Result;
Douglas Gregor7a7be652009-02-03 19:21:40 +0000915 Result.StoredKind = AmbiguousLookupStoresBasePaths;
Douglas Gregord07474b2009-01-17 01:13:24 +0000916 Result.First = reinterpret_cast<uintptr_t>(Paths);
917 Result.Last = DifferentSubobjectTypes? 1 : 0;
918 Result.Context = &Context;
919 return Result;
920 }
Douglas Gregor6beddfe2009-01-15 02:19:31 +0000921
Douglas Gregor7a7be652009-02-03 19:21:40 +0000922 template <typename Iterator>
923 static LookupResult CreateLookupResult(ASTContext &Context,
924 Iterator B, std::size_t Len) {
Douglas Gregor09be81b2009-02-04 17:27:36 +0000925 NamedDecl ** Array = new NamedDecl*[Len];
Douglas Gregor7a7be652009-02-03 19:21:40 +0000926 for (std::size_t Idx = 0; Idx < Len; ++Idx, ++B)
927 Array[Idx] = *B;
928 LookupResult Result;
929 Result.StoredKind = AmbiguousLookupStoresDecls;
930 Result.First = reinterpret_cast<uintptr_t>(Array);
931 Result.Last = reinterpret_cast<uintptr_t>(Array + Len);
932 Result.Context = &Context;
933 return Result;
934 }
935
Douglas Gregor78d70132009-01-14 22:20:51 +0000936 LookupKind getKind() const;
937
938 /// @brief Determine whether name look found something.
939 operator bool() const { return getKind() != NotFound; }
940
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000941 /// @brief Determines whether the lookup resulted in an ambiguity.
Douglas Gregor7a7be652009-02-03 19:21:40 +0000942 bool isAmbiguous() const {
943 return StoredKind == AmbiguousLookupStoresBasePaths ||
944 StoredKind == AmbiguousLookupStoresDecls;
945 }
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000946
Douglas Gregor78d70132009-01-14 22:20:51 +0000947 /// @brief Allows conversion of a lookup result into a
948 /// declaration, with the same behavior as getAsDecl.
Douglas Gregor09be81b2009-02-04 17:27:36 +0000949 operator NamedDecl*() const { return getAsDecl(); }
Douglas Gregor78d70132009-01-14 22:20:51 +0000950
Douglas Gregor09be81b2009-02-04 17:27:36 +0000951 NamedDecl* getAsDecl() const;
Douglas Gregor29dfa2f2009-01-15 00:26:24 +0000952
953 BasePaths *getBasePaths() const;
Douglas Gregorbd4b0852009-02-02 21:35:47 +0000954
955 /// \brief Iterate over the results of name lookup.
956 ///
957 /// The @c iterator class provides iteration over the results of a
958 /// non-ambiguous name lookup.
959 class iterator {
960 /// The LookupResult structure we're iterating through.
961 LookupResult *Result;
962
963 /// The current position of this iterator within the sequence of
964 /// results. This value will have the same representation as the
965 /// @c First field in the LookupResult structure.
966 mutable uintptr_t Current;
967
968 public:
Douglas Gregor09be81b2009-02-04 17:27:36 +0000969 typedef NamedDecl * value_type;
970 typedef NamedDecl * reference;
971 typedef NamedDecl * pointer;
Douglas Gregorbd4b0852009-02-02 21:35:47 +0000972 typedef std::ptrdiff_t difference_type;
973 typedef std::forward_iterator_tag iterator_category;
974
975 iterator() : Result(0), Current(0) { }
976
977 iterator(LookupResult *Res, uintptr_t Cur) : Result(Res), Current(Cur) { }
978
979 reference operator*() const;
980
981 pointer operator->() const { return **this; }
982
983 iterator &operator++();
984
985 iterator operator++(int) {
986 iterator tmp(*this);
987 ++(*this);
988 return tmp;
989 }
990
991 friend inline bool operator==(iterator const& x, iterator const& y) {
992 return x.Current == y.Current;
993 }
994
995 friend inline bool operator!=(iterator const& x, iterator const& y) {
996 return x.Current != y.Current;
997 }
998 };
999 friend class iterator;
1000
1001 iterator begin();
1002 iterator end();
Douglas Gregord7cb0372009-04-01 21:51:26 +00001003
1004 /// \brief Free the memory associated with this lookup.
1005 void Destroy();
Douglas Gregor78d70132009-01-14 22:20:51 +00001006 };
1007
Douglas Gregor7a7be652009-02-03 19:21:40 +00001008private:
1009 typedef llvm::SmallVector<LookupResult, 3> LookupResultsVecTy;
1010
1011 std::pair<bool, LookupResult> CppLookupName(Scope *S, DeclarationName Name,
1012 LookupNameKind NameKind,
1013 bool RedeclarationOnly);
Fariborz Jahanian0119fd22009-04-07 18:28:06 +00001014 ObjCMethodDecl *FindMethodInNestedImplementations(
1015 const ObjCInterfaceDecl *IFace,
1016 const Selector &Sel);
Douglas Gregor7a7be652009-02-03 19:21:40 +00001017
1018public:
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001019 /// Determines whether D is a suitable lookup result according to the
1020 /// lookup criteria.
Douglas Gregor1c52c632009-02-24 20:03:32 +00001021 static bool isAcceptableLookupResult(NamedDecl *D, LookupNameKind NameKind,
Douglas Gregorb96b92d2009-02-05 19:25:20 +00001022 unsigned IDNS) {
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001023 switch (NameKind) {
1024 case Sema::LookupOrdinaryName:
1025 case Sema::LookupTagName:
1026 case Sema::LookupMemberName:
Douglas Gregor1c52c632009-02-24 20:03:32 +00001027 case Sema::LookupRedeclarationWithLinkage: // FIXME: check linkage, scoping
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001028 return D->isInIdentifierNamespace(IDNS);
1029
Douglas Gregor48a87322009-02-04 16:44:47 +00001030 case Sema::LookupOperatorName:
1031 return D->isInIdentifierNamespace(IDNS) &&
1032 !D->getDeclContext()->isRecord();
1033
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001034 case Sema::LookupNestedNameSpecifierName:
1035 return isa<TypedefDecl>(D) || D->isInIdentifierNamespace(Decl::IDNS_Tag);
1036
1037 case Sema::LookupNamespaceName:
Anders Carlsson7c1c5482009-03-28 23:53:49 +00001038 return isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D);
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001039 }
1040
1041 assert(false &&
Douglas Gregorb96b92d2009-02-05 19:25:20 +00001042 "isAcceptableLookupResult always returns before this point");
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001043 return false;
1044 }
Douglas Gregor29dfa2f2009-01-15 00:26:24 +00001045
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001046 LookupResult LookupName(Scope *S, DeclarationName Name,
1047 LookupNameKind NameKind,
Douglas Gregor411889e2009-02-13 23:20:09 +00001048 bool RedeclarationOnly = false,
1049 bool AllowBuiltinCreation = true,
1050 SourceLocation Loc = SourceLocation());
Douglas Gregor52ae30c2009-01-30 01:04:22 +00001051 LookupResult LookupQualifiedName(DeclContext *LookupCtx, DeclarationName Name,
1052 LookupNameKind NameKind,
1053 bool RedeclarationOnly = false);
1054 LookupResult LookupParsedName(Scope *S, const CXXScopeSpec *SS,
1055 DeclarationName Name,
1056 LookupNameKind NameKind,
Douglas Gregor411889e2009-02-13 23:20:09 +00001057 bool RedeclarationOnly = false,
1058 bool AllowBuiltinCreation = true,
1059 SourceLocation Loc = SourceLocation());
Douglas Gregor3fc092f2009-03-13 00:33:25 +00001060
Douglas Gregor3fc092f2009-03-13 00:33:25 +00001061 void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S,
1062 QualType T1, QualType T2,
1063 FunctionSet &Functions);
1064
1065 void ArgumentDependentLookup(DeclarationName Name,
1066 Expr **Args, unsigned NumArgs,
1067 FunctionSet &Functions);
1068
Douglas Gregoraa1da4a2009-02-04 00:32:51 +00001069 void FindAssociatedClassesAndNamespaces(Expr **Args, unsigned NumArgs,
1070 AssociatedNamespaceSet &AssociatedNamespaces,
1071 AssociatedClassSet &AssociatedClasses);
1072
Douglas Gregor29dfa2f2009-01-15 00:26:24 +00001073 bool DiagnoseAmbiguousLookup(LookupResult &Result, DeclarationName Name,
1074 SourceLocation NameLoc,
1075 SourceRange LookupRange = SourceRange());
Douglas Gregor78d70132009-01-14 22:20:51 +00001076 //@}
1077
Ted Kremenek42730c52008-01-07 19:49:32 +00001078 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +00001079 NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
Douglas Gregor411889e2009-02-13 23:20:09 +00001080 Scope *S, bool ForRedeclaration,
1081 SourceLocation Loc);
Douglas Gregoraf8ad2b2009-01-20 01:17:11 +00001082 NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
1083 Scope *S);
Douglas Gregorb5af7382009-02-14 18:57:46 +00001084 void AddKnownFunctionAttributes(FunctionDecl *FD);
Douglas Gregor78d70132009-01-14 22:20:51 +00001085
1086 // More parsing and symbol table subroutines.
1087
Chris Lattner4b009652007-07-25 00:24:17 +00001088 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner2024f0a2008-06-29 00:16:31 +00001089 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerd7e83d82008-06-28 23:58:55 +00001090 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb2a72bb32008-02-04 02:31:56 +00001091
Steve Naroffb4f48512008-02-10 21:38:56 +00001092 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
1093 bool &IncompleteImpl);
Fariborz Jahanian4e0f6452008-12-05 18:18:52 +00001094 void WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethod,
1095 ObjCMethodDecl *IntfMethod);
Sebastian Redlb93b49c2008-11-11 11:37:55 +00001096
1097 NamespaceDecl *GetStdNamespace();
Fariborz Jahanianf96ee9e2009-01-12 19:55:42 +00001098
1099 bool isPropertyReadonly(ObjCPropertyDecl *PropertyDecl,
Steve Naroffb0bf2c92009-02-26 19:11:32 +00001100 ObjCInterfaceDecl *IDecl);
Steve Naroffb4f48512008-02-10 21:38:56 +00001101
Chris Lattner7898bf62009-01-06 07:27:21 +00001102 /// CheckProtocolMethodDefs - This routine checks unimplemented
Daniel Dunbar1d706e92008-09-04 20:01:15 +00001103 /// methods declared in protocol, and those referenced by it.
1104 /// \param IDecl - Used for checking for methods which may have been
1105 /// inherited.
Steve Naroffb268d2a2008-02-08 22:06:17 +00001106 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
1107 ObjCProtocolDecl *PDecl,
Fariborz Jahaniand3952f32007-10-02 20:06:01 +00001108 bool& IncompleteImpl,
Steve Naroff7711ee32007-10-08 21:05:34 +00001109 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar1d706e92008-09-04 20:01:15 +00001110 const llvm::DenseSet<Selector> &ClsMap,
1111 ObjCInterfaceDecl *IDecl);
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +00001112
Steve Naroff89529b12007-10-02 21:43:37 +00001113 /// CheckImplementationIvars - This routine checks if the instance variables
1114 /// listed in the implelementation match those listed in the interface.
Ted Kremenek42730c52008-01-07 19:49:32 +00001115 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
1116 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroffb4f48512008-02-10 21:38:56 +00001117 SourceLocation Loc);
Steve Naroff89529b12007-10-02 21:43:37 +00001118
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +00001119 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
Chris Lattner7cc13bf2009-03-01 00:56:52 +00001120 /// remains unimplemented in the class or category @implementation.
1121 void ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl,
1122 ObjCContainerDecl* IDecl,
1123 bool IncompleteImpl = false);
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +00001124
Fariborz Jahanian67907bd2007-10-05 18:00:57 +00001125 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
1126 /// true, or false, accordingly.
Ted Kremenek42730c52008-01-07 19:49:32 +00001127 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Naroffb91afca2008-10-21 10:37:50 +00001128 const ObjCMethodDecl *PrevMethod,
1129 bool matchBasedOnSizeAndAlignment = false);
Steve Naroffee1de132007-10-10 21:53:07 +00001130
Steve Naroff8255b042007-10-14 00:58:41 +00001131 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
1132 /// unit are added to a global pool. This allows us to efficiently associate
1133 /// a selector with a method declaraation for purposes of typechecking
1134 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek42730c52008-01-07 19:49:32 +00001135 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff8255b042007-10-14 00:58:41 +00001136
Steve Naroff68354f32008-09-30 14:38:43 +00001137 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
1138 /// there are multiple signatures.
1139 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
1140
Steve Naroff8255b042007-10-14 00:58:41 +00001141 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek42730c52008-01-07 19:49:32 +00001142 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner4b009652007-07-25 00:24:17 +00001143 //===--------------------------------------------------------------------===//
1144 // Statement Parsing Callbacks: SemaStmt.cpp.
1145public:
Sebastian Redl76b9ddb2008-12-21 12:04:03 +00001146 virtual OwningStmtResult ActOnExprStmt(ExprArg Expr);
1147
1148 virtual OwningStmtResult ActOnNullStmt(SourceLocation SemiLoc);
1149 virtual OwningStmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
1150 MultiStmtArg Elts,
1151 bool isStmtExpr);
Chris Lattnera17991f2009-03-29 16:50:03 +00001152 virtual OwningStmtResult ActOnDeclStmt(DeclGroupPtrTy Decl,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001153 SourceLocation StartLoc,
Sebastian Redl76b9ddb2008-12-21 12:04:03 +00001154 SourceLocation EndLoc);
Sebastian Redl0a23e8f2008-12-28 16:13:43 +00001155 virtual OwningStmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprArg LHSVal,
1156 SourceLocation DotDotDotLoc, ExprArg RHSVal,
Chris Lattnerdaac6942009-03-04 04:23:07 +00001157 SourceLocation ColonLoc);
1158 virtual void ActOnCaseStmtBody(StmtTy *CaseStmt, StmtArg SubStmt);
1159
Sebastian Redl0a23e8f2008-12-28 16:13:43 +00001160 virtual OwningStmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
1161 SourceLocation ColonLoc,
1162 StmtArg SubStmt, Scope *CurScope);
Sebastian Redl2437ec62009-01-11 00:38:46 +00001163 virtual OwningStmtResult ActOnLabelStmt(SourceLocation IdentLoc,
1164 IdentifierInfo *II,
1165 SourceLocation ColonLoc,
1166 StmtArg SubStmt);
1167 virtual OwningStmtResult ActOnIfStmt(SourceLocation IfLoc, ExprArg CondVal,
1168 StmtArg ThenVal, SourceLocation ElseLoc,
1169 StmtArg ElseVal);
1170 virtual OwningStmtResult ActOnStartOfSwitchStmt(ExprArg Cond);
1171 virtual OwningStmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
1172 StmtArg Switch, StmtArg Body);
Sebastian Redl19c74d32009-01-16 23:28:06 +00001173 virtual OwningStmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprArg Cond,
1174 StmtArg Body);
1175 virtual OwningStmtResult ActOnDoStmt(SourceLocation DoLoc, StmtArg Body,
1176 SourceLocation WhileLoc, ExprArg Cond);
1177
1178 virtual OwningStmtResult ActOnForStmt(SourceLocation ForLoc,
1179 SourceLocation LParenLoc,
1180 StmtArg First, ExprArg Second,
1181 ExprArg Third, SourceLocation RParenLoc,
1182 StmtArg Body);
1183 virtual OwningStmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
1184 SourceLocation LParenLoc,
1185 StmtArg First, ExprArg Second,
1186 SourceLocation RParenLoc, StmtArg Body);
Sebastian Redl539eb572009-01-18 13:19:59 +00001187
1188 virtual OwningStmtResult ActOnGotoStmt(SourceLocation GotoLoc,
1189 SourceLocation LabelLoc,
1190 IdentifierInfo *LabelII);
1191 virtual OwningStmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
1192 SourceLocation StarLoc,
1193 ExprArg DestExp);
1194 virtual OwningStmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
1195 Scope *CurScope);
1196 virtual OwningStmtResult ActOnBreakStmt(SourceLocation GotoLoc,
1197 Scope *CurScope);
1198
1199 virtual OwningStmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
1200 ExprArg RetValExp);
1201 OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
1202 Expr *RetValExp);
1203
Sebastian Redlc6b86332009-01-18 16:53:17 +00001204 virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
1205 bool IsSimple,
1206 bool IsVolatile,
1207 unsigned NumOutputs,
1208 unsigned NumInputs,
1209 std::string *Names,
1210 MultiExprArg Constraints,
1211 MultiExprArg Exprs,
1212 ExprArg AsmString,
1213 MultiExprArg Clobbers,
1214 SourceLocation RParenLoc);
Sebastian Redlb3860a72009-01-18 17:43:11 +00001215
1216 virtual OwningStmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
1217 SourceLocation RParen,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001218 DeclPtrTy Parm, StmtArg Body,
Sebastian Redlb3860a72009-01-18 17:43:11 +00001219 StmtArg CatchList);
1220
1221 virtual OwningStmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
1222 StmtArg Body);
1223
1224 virtual OwningStmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
1225 StmtArg Try,
1226 StmtArg Catch, StmtArg Finally);
1227
1228 virtual OwningStmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Steve Naroff590fe482009-02-11 20:05:44 +00001229 ExprArg Throw,
1230 Scope *CurScope);
Sebastian Redlb3860a72009-01-18 17:43:11 +00001231 virtual OwningStmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
1232 ExprArg SynchExpr,
1233 StmtArg SynchBody);
Sebastian Redlb12ac332008-12-21 16:41:36 +00001234
Chris Lattner5261d0c2009-03-28 19:18:32 +00001235 virtual DeclPtrTy ActOnExceptionDeclarator(Scope *S, Declarator &D);
Sebastian Redl743c8162008-12-22 19:15:10 +00001236 virtual OwningStmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001237 DeclPtrTy ExDecl,
Sebastian Redl743c8162008-12-22 19:15:10 +00001238 StmtArg HandlerBlock);
Sebastian Redl237116b2008-12-22 21:35:02 +00001239 virtual OwningStmtResult ActOnCXXTryBlock(SourceLocation TryLoc,
1240 StmtArg TryBlock,
1241 MultiStmtArg Handlers);
Sebastian Redlb12ac332008-12-21 16:41:36 +00001242
Chris Lattner4b009652007-07-25 00:24:17 +00001243 //===--------------------------------------------------------------------===//
1244 // Expression Parsing Callbacks: SemaExpr.cpp.
1245
Douglas Gregoraa57e862009-02-18 21:56:37 +00001246 bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
Chris Lattner2cb744b2009-02-15 22:43:40 +00001247
Chris Lattner4b009652007-07-25 00:24:17 +00001248 // Primary Expressions.
Douglas Gregor3bb30002009-02-26 21:00:50 +00001249 virtual SourceRange getExprRange(ExprTy *E) const;
1250
Sebastian Redlcd883f72009-01-18 18:53:16 +00001251 virtual OwningExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
1252 IdentifierInfo &II,
1253 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001254 const CXXScopeSpec *SS = 0,
1255 bool isAddressOfOperand = false);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001256 virtual OwningExprResult ActOnCXXOperatorFunctionIdExpr(Scope *S,
Douglas Gregor24094772008-11-19 19:09:45 +00001257 SourceLocation OperatorLoc,
1258 OverloadedOperatorKind Op,
1259 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001260 const CXXScopeSpec &SS,
1261 bool isAddressOfOperand);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001262 virtual OwningExprResult ActOnCXXConversionFunctionExpr(Scope *S,
Douglas Gregor24094772008-11-19 19:09:45 +00001263 SourceLocation OperatorLoc,
1264 TypeTy *Ty,
1265 bool HasTrailingLParen,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001266 const CXXScopeSpec &SS,
1267 bool isAddressOfOperand);
Douglas Gregor566782a2009-01-06 05:10:23 +00001268 DeclRefExpr *BuildDeclRefExpr(NamedDecl *D, QualType Ty, SourceLocation Loc,
1269 bool TypeDependent, bool ValueDependent,
1270 const CXXScopeSpec *SS = 0);
Douglas Gregorcc94ab72009-04-15 06:41:24 +00001271 VarDecl *BuildAnonymousStructUnionMemberPath(FieldDecl *Field,
1272 llvm::SmallVectorImpl<FieldDecl *> &Path);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001273 OwningExprResult
Douglas Gregor723d3332009-01-07 00:43:41 +00001274 BuildAnonymousStructUnionMemberReference(SourceLocation Loc,
1275 FieldDecl *Field,
1276 Expr *BaseObjectExpr = 0,
1277 SourceLocation OpLoc = SourceLocation());
Sebastian Redlcd883f72009-01-18 18:53:16 +00001278 OwningExprResult ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
1279 DeclarationName Name,
1280 bool HasTrailingLParen,
1281 const CXXScopeSpec *SS,
Sebastian Redl0c9da212009-02-03 20:19:35 +00001282 bool isAddressOfOperand = false);
Douglas Gregoraee3bf82008-11-18 15:03:34 +00001283
Sebastian Redlcd883f72009-01-18 18:53:16 +00001284 virtual OwningExprResult ActOnPredefinedExpr(SourceLocation Loc,
1285 tok::TokenKind Kind);
1286 virtual OwningExprResult ActOnNumericConstant(const Token &);
1287 virtual OwningExprResult ActOnCharacterConstant(const Token &);
1288 virtual OwningExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
1289 ExprArg Val);
Chris Lattner4b009652007-07-25 00:24:17 +00001290
Steve Naroff87d58b42007-09-16 03:34:24 +00001291 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner4b009652007-07-25 00:24:17 +00001292 /// fragments (e.g. "foo" "bar" L"baz").
Sebastian Redl8b769972009-01-19 00:08:26 +00001293 virtual OwningExprResult ActOnStringLiteral(const Token *Toks,
1294 unsigned NumToks);
Sebastian Redlcd883f72009-01-18 18:53:16 +00001295
Chris Lattner4b009652007-07-25 00:24:17 +00001296 // Binary/Unary Operators. 'Tok' is the token for the operator.
Douglas Gregorc78182d2009-03-13 23:49:33 +00001297 OwningExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc,
1298 unsigned OpcIn,
1299 ExprArg InputArg);
Sebastian Redl8b769972009-01-19 00:08:26 +00001300 virtual OwningExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc,
1301 tok::TokenKind Op, ExprArg Input);
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001302
Douglas Gregor396f1142009-03-13 21:01:28 +00001303 OwningExprResult CreateSizeOfAlignOfExpr(QualType T, SourceLocation OpLoc,
1304 bool isSizeOf, SourceRange R);
1305 OwningExprResult CreateSizeOfAlignOfExpr(Expr *E, SourceLocation OpLoc,
1306 bool isSizeOf, SourceRange R);
Douglas Gregorc78182d2009-03-13 23:49:33 +00001307 virtual OwningExprResult
1308 ActOnSizeOfAlignOfExpr(SourceLocation OpLoc, bool isSizeof, bool isType,
1309 void *TyOrEx, const SourceRange &ArgRange);
Douglas Gregor396f1142009-03-13 21:01:28 +00001310
Chris Lattner8d9f7962009-01-24 20:17:12 +00001311 bool CheckAlignOfExpr(Expr *E, SourceLocation OpLoc, const SourceRange &R);
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001312 bool CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
1313 const SourceRange &R, bool isSizeof);
Sebastian Redl8b769972009-01-19 00:08:26 +00001314
1315 virtual OwningExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc,
1316 tok::TokenKind Kind,
1317 ExprArg Input);
1318
1319 virtual OwningExprResult ActOnArraySubscriptExpr(Scope *S, ExprArg Base,
1320 SourceLocation LLoc,
1321 ExprArg Idx,
1322 SourceLocation RLoc);
1323 virtual OwningExprResult ActOnMemberReferenceExpr(Scope *S, ExprArg Base,
1324 SourceLocation OpLoc,
1325 tok::TokenKind OpKind,
1326 SourceLocation MemberLoc,
Fariborz Jahanian0cc2ac12009-03-04 22:30:12 +00001327 IdentifierInfo &Member,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001328 DeclPtrTy ImplDecl);
Sebastian Redl8b769972009-01-19 00:08:26 +00001329 bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
Douglas Gregor3257fb52008-12-22 05:46:06 +00001330 FunctionDecl *FDecl,
Douglas Gregor4fa58902009-02-26 23:50:07 +00001331 const FunctionProtoType *Proto,
Douglas Gregor3257fb52008-12-22 05:46:06 +00001332 Expr **Args, unsigned NumArgs,
1333 SourceLocation RParenLoc);
Sebastian Redl8b769972009-01-19 00:08:26 +00001334
Steve Naroff87d58b42007-09-16 03:34:24 +00001335 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner4b009652007-07-25 00:24:17 +00001336 /// This provides the location of the left/right parens and a list of comma
1337 /// locations.
Sebastian Redl8b769972009-01-19 00:08:26 +00001338 virtual OwningExprResult ActOnCallExpr(Scope *S, ExprArg Fn,
1339 SourceLocation LParenLoc,
1340 MultiExprArg Args,
1341 SourceLocation *CommaLocs,
1342 SourceLocation RParenLoc);
1343
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001344 virtual OwningExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
1345 SourceLocation RParenLoc, ExprArg Op);
1346
1347 virtual OwningExprResult ActOnCompoundLiteral(SourceLocation LParenLoc,
1348 TypeTy *Ty,
1349 SourceLocation RParenLoc,
1350 ExprArg Op);
1351
1352 virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
1353 MultiExprArg InitList,
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001354 SourceLocation RParenLoc);
1355
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001356 virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
1357 SourceLocation Loc,
Douglas Gregor5f34f0e2009-03-28 00:41:23 +00001358 bool GNUSyntax,
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001359 OwningExprResult Init);
1360
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001361 virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
1362 tok::TokenKind Kind,
1363 ExprArg LHS, ExprArg RHS);
1364 OwningExprResult CreateBuiltinBinOp(SourceLocation TokLoc,
1365 unsigned Opc, Expr *lhs, Expr *rhs);
Douglas Gregord7f915e2008-11-06 23:29:22 +00001366
Steve Naroff87d58b42007-09-16 03:34:24 +00001367 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner4b009652007-07-25 00:24:17 +00001368 /// in the case of a the GNU conditional expr extension.
Sebastian Redl5457c5e2009-01-19 22:31:54 +00001369 virtual OwningExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
1370 SourceLocation ColonLoc,
1371 ExprArg Cond, ExprArg LHS,
1372 ExprArg RHS);
Chris Lattner4b009652007-07-25 00:24:17 +00001373
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001374 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001375 virtual OwningExprResult ActOnAddrLabel(SourceLocation OpLoc,
1376 SourceLocation LabLoc,
1377 IdentifierInfo *LabelII);
1378
1379 virtual OwningExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtArg SubStmt,
1380 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +00001381
1382 /// __builtin_offsetof(type, a.b[123][456].c)
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001383 virtual OwningExprResult ActOnBuiltinOffsetOf(Scope *S,
1384 SourceLocation BuiltinLoc,
1385 SourceLocation TypeLoc,
1386 TypeTy *Arg1,
1387 OffsetOfComponent *CompPtr,
1388 unsigned NumComponents,
1389 SourceLocation RParenLoc);
1390
Steve Naroff63bad2d2007-08-01 22:05:33 +00001391 // __builtin_types_compatible_p(type1, type2)
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001392 virtual OwningExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
1393 TypeTy *arg1, TypeTy *arg2,
1394 SourceLocation RPLoc);
1395
Steve Naroff93c53012007-08-03 21:21:27 +00001396 // __builtin_choose_expr(constExpr, expr1, expr2)
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001397 virtual OwningExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
1398 ExprArg cond, ExprArg expr1,
1399 ExprArg expr2, SourceLocation RPLoc);
1400
Anders Carlsson36760332007-10-15 20:28:48 +00001401 // __builtin_va_arg(expr, type)
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001402 virtual OwningExprResult ActOnVAArg(SourceLocation BuiltinLoc,
1403 ExprArg expr, TypeTy *type,
1404 SourceLocation RPLoc);
Steve Naroff52a81c02008-09-03 18:15:37 +00001405
Douglas Gregorad4b3792008-11-29 04:51:27 +00001406 // __null
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001407 virtual OwningExprResult ActOnGNUNullExpr(SourceLocation TokenLoc);
Douglas Gregorad4b3792008-11-29 04:51:27 +00001408
Steve Naroff52a81c02008-09-03 18:15:37 +00001409 //===------------------------- "Block" Extension ------------------------===//
1410
1411 /// ActOnBlockStart - This callback is invoked when a block literal is
1412 /// started.
Steve Naroff52059382008-10-10 01:28:17 +00001413 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001414
Steve Naroff52059382008-10-10 01:28:17 +00001415 /// ActOnBlockArguments - This callback allows processing of block arguments.
1416 /// If there are no arguments, this is still invoked.
Mike Stumpc1fddff2009-02-04 22:31:32 +00001417 virtual void ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope);
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001418
Steve Naroff52a81c02008-09-03 18:15:37 +00001419 /// ActOnBlockError - If there is an error parsing a block, this callback
1420 /// is invoked to pop the information about the block from the action impl.
1421 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001422
Steve Naroff52a81c02008-09-03 18:15:37 +00001423 /// ActOnBlockStmtExpr - This is called when the body of a block statement
1424 /// literal was successfully completed. ^(int x){...}
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001425 virtual OwningExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc,
1426 StmtArg Body, Scope *CurScope);
Steve Naroff52a81c02008-09-03 18:15:37 +00001427
Chris Lattner2cb744b2009-02-15 22:43:40 +00001428 //===---------------------------- C++ Features --------------------------===//
1429
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +00001430 // Act on C++ namespaces
Chris Lattner5261d0c2009-03-28 19:18:32 +00001431 virtual DeclPtrTy ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
1432 IdentifierInfo *Ident,
1433 SourceLocation LBrace);
1434 virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace);
Argiris Kirtzidis03e6aaf2008-04-27 13:50:30 +00001435
Chris Lattner5261d0c2009-03-28 19:18:32 +00001436 virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope,
1437 SourceLocation UsingLoc,
1438 SourceLocation NamespcLoc,
1439 const CXXScopeSpec &SS,
1440 SourceLocation IdentLoc,
1441 IdentifierInfo *NamespcName,
1442 AttributeList *AttrList);
Anders Carlsson8cffcd62009-03-28 05:27:17 +00001443
Douglas Gregor7a7be652009-02-03 19:21:40 +00001444 void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir);
1445
Chris Lattner5261d0c2009-03-28 19:18:32 +00001446 virtual DeclPtrTy ActOnNamespaceAliasDef(Scope *CurScope,
Anders Carlsson26de7882009-03-28 22:53:22 +00001447 SourceLocation NamespaceLoc,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001448 SourceLocation AliasLoc,
1449 IdentifierInfo *Alias,
1450 const CXXScopeSpec &SS,
Anders Carlsson26de7882009-03-28 22:53:22 +00001451 SourceLocation IdentLoc,
1452 IdentifierInfo *Ident);
Anders Carlsson8cffcd62009-03-28 05:27:17 +00001453
Argiris Kirtzidis9e55d462008-10-06 17:10:33 +00001454 /// AddCXXDirectInitializerToDecl - This action is called immediately after
1455 /// ActOnDeclarator, when a C++ direct initializer is present.
1456 /// e.g: "int x(1);"
Chris Lattner5261d0c2009-03-28 19:18:32 +00001457 virtual void AddCXXDirectInitializerToDecl(DeclPtrTy Dcl,
Argiris Kirtzidis9e55d462008-10-06 17:10:33 +00001458 SourceLocation LParenLoc,
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001459 MultiExprArg Exprs,
Argiris Kirtzidis9e55d462008-10-06 17:10:33 +00001460 SourceLocation *CommaLocs,
1461 SourceLocation RParenLoc);
1462
Anders Carlsson05e59652009-04-16 23:50:50 +00001463 /// InitializeVarWithConstructor - Creates an implicit
1464 /// CXXTemporaryObjectExpr and sets it as the passed in VarDecl initializer.
1465 void InitializeVarWithConstructor(VarDecl *VD,
1466 CXXConstructorDecl *Constructor,
1467 QualType DeclInitType,
1468 Expr **Exprs, unsigned NumExprs);
1469
Douglas Gregor6428e762008-11-05 15:29:30 +00001470 /// InitializationKind - Represents which kind of C++ initialization
1471 /// [dcl.init] a routine is to perform.
1472 enum InitializationKind {
1473 IK_Direct, ///< Direct initialization
1474 IK_Copy, ///< Copy initialization
1475 IK_Default ///< Default initialization
1476 };
1477
Douglas Gregor5870a952008-11-03 20:45:27 +00001478 CXXConstructorDecl *
Douglas Gregor6428e762008-11-05 15:29:30 +00001479 PerformInitializationByConstructor(QualType ClassType,
1480 Expr **Args, unsigned NumArgs,
1481 SourceLocation Loc, SourceRange Range,
Chris Lattner271d4c22008-11-24 05:29:24 +00001482 DeclarationName InitEntity,
Douglas Gregor6428e762008-11-05 15:29:30 +00001483 InitializationKind Kind);
Douglas Gregor5870a952008-11-03 20:45:27 +00001484
Douglas Gregor21a04f32008-10-27 19:41:14 +00001485 /// ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const}_cast's.
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001486 virtual OwningExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
1487 tok::TokenKind Kind,
1488 SourceLocation LAngleBracketLoc,
1489 TypeTy *Ty,
1490 SourceLocation RAngleBracketLoc,
1491 SourceLocation LParenLoc,
1492 ExprArg E,
1493 SourceLocation RParenLoc);
Chris Lattner4b009652007-07-25 00:24:17 +00001494
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001495 /// ActOnCXXTypeid - Parse typeid( something ).
1496 virtual OwningExprResult ActOnCXXTypeid(SourceLocation OpLoc,
1497 SourceLocation LParenLoc, bool isType,
1498 void *TyOrExpr,
1499 SourceLocation RParenLoc);
Sebastian Redlb93b49c2008-11-11 11:37:55 +00001500
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001501 //// ActOnCXXThis - Parse 'this' pointer.
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001502 virtual OwningExprResult ActOnCXXThis(SourceLocation ThisLoc);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001503
Steve Naroff5cbb02f2007-09-16 14:56:35 +00001504 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001505 virtual OwningExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
1506 tok::TokenKind Kind);
1507
Chris Lattnera7447ba2008-02-26 00:51:44 +00001508 //// ActOnCXXThrow - Parse throw expressions.
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001509 virtual OwningExprResult ActOnCXXThrow(SourceLocation OpLoc,
1510 ExprArg expr);
Chris Lattnera7447ba2008-02-26 00:51:44 +00001511
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001512 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
1513 /// Can be interpreted either as function-style casting ("int(x)")
1514 /// or class type construction ("ClassType(x,y,z)")
1515 /// or creation of a value-initialized type ("int()").
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001516 virtual OwningExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
1517 TypeTy *TypeRep,
1518 SourceLocation LParenLoc,
1519 MultiExprArg Exprs,
1520 SourceLocation *CommaLocs,
1521 SourceLocation RParenLoc);
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001522
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001523 /// ActOnCXXNew - Parsed a C++ 'new' expression.
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001524 virtual OwningExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
1525 SourceLocation PlacementLParen,
1526 MultiExprArg PlacementArgs,
1527 SourceLocation PlacementRParen,
1528 bool ParenTypeId, Declarator &D,
1529 SourceLocation ConstructorLParen,
1530 MultiExprArg ConstructorArgs,
1531 SourceLocation ConstructorRParen);
Sebastian Redl66df3ef2008-12-02 14:43:59 +00001532 bool CheckAllocatedType(QualType AllocType, const Declarator &D);
Sebastian Redl3b7ec4b2009-02-09 18:24:27 +00001533 bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
1534 bool UseGlobal, QualType AllocType, bool IsArray,
Sebastian Redlb5ee8742008-12-03 20:26:15 +00001535 Expr **PlaceArgs, unsigned NumPlaceArgs,
1536 FunctionDecl *&OperatorNew,
1537 FunctionDecl *&OperatorDelete);
Sebastian Redl3b7ec4b2009-02-09 18:24:27 +00001538 bool FindAllocationOverload(SourceLocation StartLoc, SourceRange Range,
1539 DeclarationName Name, Expr** Args,
1540 unsigned NumArgs, DeclContext *Ctx,
Sebastian Redlec5f3262008-12-04 22:20:51 +00001541 bool AllowMissing, FunctionDecl *&Operator);
Sebastian Redlb5ee8742008-12-03 20:26:15 +00001542 void DeclareGlobalNewDelete();
1543 void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return,
1544 QualType Argument);
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001545
1546 /// ActOnCXXDelete - Parsed a C++ 'delete' expression
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001547 virtual OwningExprResult ActOnCXXDelete(SourceLocation StartLoc,
1548 bool UseGlobal, bool ArrayForm,
1549 ExprArg Operand);
Sebastian Redl19fec9d2008-11-21 19:14:01 +00001550
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00001551 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
1552 /// C++ if/switch/while/for statement.
1553 /// e.g: "if (int x = f()) {...}"
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001554 virtual OwningExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00001555 SourceLocation StartLoc,
1556 Declarator &D,
1557 SourceLocation EqualLoc,
Sebastian Redl76bb8ec2009-03-15 17:47:39 +00001558 ExprArg AssignExprVal);
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00001559
Sebastian Redl39c0f6f2009-01-05 20:52:13 +00001560 /// ActOnUnaryTypeTrait - Parsed one of the unary type trait support
1561 /// pseudo-functions.
1562 virtual OwningExprResult ActOnUnaryTypeTrait(UnaryTypeTrait OTT,
1563 SourceLocation KWLoc,
1564 SourceLocation LParen,
1565 TypeTy *Ty,
1566 SourceLocation RParen);
1567
Douglas Gregor6e7c27c2009-03-11 16:48:53 +00001568 bool RequireCompleteDeclContext(const CXXScopeSpec &SS);
Douglas Gregor734b4ba2009-03-19 00:18:19 +00001569
1570 DeclContext *computeDeclContext(const CXXScopeSpec &SS);
Douglas Gregor47bde7c2009-03-19 17:26:29 +00001571 bool isDependentScopeSpecifier(const CXXScopeSpec &SS);
Douglas Gregor253fc4d2009-03-18 00:36:05 +00001572
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001573 /// ActOnCXXGlobalScopeSpecifier - Return the object that represents the
1574 /// global scope ('::').
1575 virtual CXXScopeTy *ActOnCXXGlobalScopeSpecifier(Scope *S,
1576 SourceLocation CCLoc);
1577
1578 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1579 /// nested-name-specifier. e.g. for "foo::bar::" we parsed "foo::" and now
1580 /// we want to resolve "bar::". 'SS' is empty or the previously parsed
1581 /// nested-name part ("foo::"), 'IdLoc' is the source location of 'bar',
1582 /// 'CCLoc' is the location of '::' and 'II' is the identifier for 'bar'.
1583 /// Returns a CXXScopeTy* object representing the C++ scope.
1584 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1585 const CXXScopeSpec &SS,
1586 SourceLocation IdLoc,
1587 SourceLocation CCLoc,
Douglas Gregorb0212bd2008-11-17 20:34:05 +00001588 IdentifierInfo &II);
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001589
Douglas Gregor0c281a82009-02-25 19:37:18 +00001590 /// ActOnCXXNestedNameSpecifier - Called during parsing of a
1591 /// nested-name-specifier that involves a template-id, e.g.,
1592 /// "foo::bar<int, float>::", and now we need to build a scope
1593 /// specifier. \p SS is empty or the previously parsed nested-name
1594 /// part ("foo::"), \p Type is the already-parsed class template
1595 /// specialization (or other template-id that names a type), \p
1596 /// TypeRange is the source range where the type is located, and \p
1597 /// CCLoc is the location of the trailing '::'.
1598 virtual CXXScopeTy *ActOnCXXNestedNameSpecifier(Scope *S,
1599 const CXXScopeSpec &SS,
1600 TypeTy *Type,
1601 SourceRange TypeRange,
1602 SourceLocation CCLoc);
1603
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001604 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1605 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1606 /// After this method is called, according to [C++ 3.4.3p3], names should be
1607 /// looked up in the declarator-id's scope, until the declarator is parsed and
1608 /// ActOnCXXExitDeclaratorScope is called.
1609 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1610 virtual void ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
1611
1612 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1613 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1614 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1615 /// Used to indicate that names should revert to being looked up in the
1616 /// defining scope.
Douglas Gregor24effa82008-12-16 00:38:16 +00001617 virtual void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS);
Argiris Kirtzidis054a2632008-11-08 17:17:31 +00001618
Anders Carlssona66cad42007-08-21 17:43:55 +00001619 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerddd3e632007-12-12 01:04:12 +00001620 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
1621 ExprTy **Strings,
1622 unsigned NumStrings);
Anders Carlsson8be1d402007-08-22 15:14:15 +00001623 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattnercfd61c82007-10-16 22:51:17 +00001624 SourceLocation EncodeLoc,
Anders Carlsson8be1d402007-08-22 15:14:15 +00001625 SourceLocation LParenLoc,
1626 TypeTy *Ty,
1627 SourceLocation RParenLoc);
1628
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001629 // ParseObjCSelectorExpression - Build selector expression for @selector
1630 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
1631 SourceLocation AtLoc,
Fariborz Jahanian957448a2007-10-16 23:21:02 +00001632 SourceLocation SelLoc,
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001633 SourceLocation LParenLoc,
1634 SourceLocation RParenLoc);
1635
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001636 // ParseObjCProtocolExpression - Build protocol expression for @protocol
1637 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
1638 SourceLocation AtLoc,
1639 SourceLocation ProtoLoc,
1640 SourceLocation LParenLoc,
1641 SourceLocation RParenLoc);
Douglas Gregorec93f442008-04-13 21:30:24 +00001642
1643 //===--------------------------------------------------------------------===//
Douglas Gregord8028382009-01-05 19:45:36 +00001644 // C++ Declarations
1645 //
Chris Lattner5261d0c2009-03-28 19:18:32 +00001646 virtual DeclPtrTy ActOnStartLinkageSpecification(Scope *S,
1647 SourceLocation ExternLoc,
1648 SourceLocation LangLoc,
1649 const char *Lang,
1650 unsigned StrSize,
1651 SourceLocation LBraceLoc);
1652 virtual DeclPtrTy ActOnFinishLinkageSpecification(Scope *S,
1653 DeclPtrTy LinkageSpec,
1654 SourceLocation RBraceLoc);
Douglas Gregord8028382009-01-05 19:45:36 +00001655
1656
1657 //===--------------------------------------------------------------------===//
Douglas Gregorec93f442008-04-13 21:30:24 +00001658 // C++ Classes
1659 //
Argiris Kirtzidis311db8c2008-11-08 16:45:02 +00001660 virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S,
1661 const CXXScopeSpec *SS);
Sebastian Redla55834a2009-04-12 17:16:29 +00001662
Chris Lattner5261d0c2009-03-28 19:18:32 +00001663 virtual DeclPtrTy ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
1664 Declarator &D,
1665 ExprTy *BitfieldWidth,
Sebastian Redla55834a2009-04-12 17:16:29 +00001666 ExprTy *Init,
1667 bool Deleted = false);
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001668
Chris Lattner5261d0c2009-03-28 19:18:32 +00001669 virtual MemInitResult ActOnMemInitializer(DeclPtrTy ConstructorD,
Douglas Gregora65e8dd2008-11-05 04:29:56 +00001670 Scope *S,
1671 IdentifierInfo *MemberOrBase,
1672 SourceLocation IdLoc,
1673 SourceLocation LParenLoc,
1674 ExprTy **Args, unsigned NumArgs,
1675 SourceLocation *CommaLocs,
1676 SourceLocation RParenLoc);
1677
Douglas Gregore640ab62008-11-03 17:51:48 +00001678 void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl);
1679
Chris Lattner5261d0c2009-03-28 19:18:32 +00001680 virtual void ActOnMemInitializers(DeclPtrTy ConstructorDecl,
Anders Carlssonc7f87202009-03-25 02:58:17 +00001681 SourceLocation ColonLoc,
1682 MemInitTy **MemInits, unsigned NumMemInits);
1683
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001684 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001685 DeclPtrTy TagDecl,
Argiris Kirtzidis38f16712008-07-01 10:37:29 +00001686 SourceLocation LBrac,
1687 SourceLocation RBrac);
1688
Chris Lattner5261d0c2009-03-28 19:18:32 +00001689 virtual void ActOnStartDelayedCXXMethodDeclaration(Scope *S,
1690 DeclPtrTy Method);
1691 virtual void ActOnDelayedCXXMethodParameter(Scope *S, DeclPtrTy Param);
1692 virtual void ActOnFinishDelayedCXXMethodDeclaration(Scope *S,
1693 DeclPtrTy Method);
Douglas Gregor605de8d2008-12-16 21:30:33 +00001694
Chris Lattner5261d0c2009-03-28 19:18:32 +00001695 virtual DeclPtrTy ActOnStaticAssertDeclaration(SourceLocation AssertLoc,
1696 ExprArg AssertExpr,
1697 ExprArg AssertMessageExpr);
Anders Carlssoned691562009-03-14 00:25:26 +00001698
Douglas Gregor8210a8e2008-11-05 20:51:48 +00001699 bool CheckConstructorDeclarator(Declarator &D, QualType &R,
1700 FunctionDecl::StorageClass& SC);
Douglas Gregor605de8d2008-12-16 21:30:33 +00001701 bool CheckConstructor(CXXConstructorDecl *Constructor);
Douglas Gregor8210a8e2008-11-05 20:51:48 +00001702 bool CheckDestructorDeclarator(Declarator &D, QualType &R,
1703 FunctionDecl::StorageClass& SC);
Douglas Gregor3ef6c972008-11-07 20:08:42 +00001704 bool CheckConversionDeclarator(Declarator &D, QualType &R,
1705 FunctionDecl::StorageClass& SC);
Chris Lattner5261d0c2009-03-28 19:18:32 +00001706 DeclPtrTy ActOnConversionDeclarator(CXXConversionDecl *Conversion);
Douglas Gregorf15ac4b2008-10-31 09:07:45 +00001707
Douglas Gregor14046502008-10-23 00:40:37 +00001708 //===--------------------------------------------------------------------===//
1709 // C++ Derived Classes
1710 //
1711
1712 /// ActOnBaseSpecifier - Parsed a base specifier
Douglas Gregored3a3982009-03-03 04:44:36 +00001713 CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class,
1714 SourceRange SpecifierRange,
1715 bool Virtual, AccessSpecifier Access,
1716 QualType BaseType,
1717 SourceLocation BaseLoc);
Chris Lattner5261d0c2009-03-28 19:18:32 +00001718 virtual BaseResult ActOnBaseSpecifier(DeclPtrTy classdecl,
Douglas Gregor14046502008-10-23 00:40:37 +00001719 SourceRange SpecifierRange,
1720 bool Virtual, AccessSpecifier Access,
Douglas Gregored3a3982009-03-03 04:44:36 +00001721 TypeTy *basetype, SourceLocation
1722 BaseLoc);
Douglas Gregor14046502008-10-23 00:40:37 +00001723
Douglas Gregored3a3982009-03-03 04:44:36 +00001724 bool AttachBaseSpecifiers(CXXRecordDecl *Class, CXXBaseSpecifier **Bases,
1725 unsigned NumBases);
Chris Lattner5261d0c2009-03-28 19:18:32 +00001726 virtual void ActOnBaseSpecifiers(DeclPtrTy ClassDecl, BaseTy **Bases,
Douglas Gregor14046502008-10-23 00:40:37 +00001727 unsigned NumBases);
1728
1729 bool IsDerivedFrom(QualType Derived, QualType Base);
Douglas Gregorbb461502008-10-24 04:54:22 +00001730 bool IsDerivedFrom(QualType Derived, QualType Base, BasePaths &Paths);
Douglas Gregor29dfa2f2009-01-15 00:26:24 +00001731 bool LookupInBases(CXXRecordDecl *Class, const MemberLookupCriteria& Criteria,
1732 BasePaths &Paths);
Douglas Gregor651d1cc2008-10-24 16:17:19 +00001733 bool CheckDerivedToBaseConversion(QualType Derived, QualType Base,
1734 SourceLocation Loc, SourceRange Range);
Douglas Gregorb9ef0552009-01-16 00:38:09 +00001735 std::string getAmbiguousPathsDisplayString(BasePaths &Paths);
Douglas Gregorec93f442008-04-13 21:30:24 +00001736
Anders Carlsson9aa04122009-03-27 05:05:05 +00001737 //===--------------------------------------------------------------------===//
1738 // C++ Access Control
1739 //
1740
1741 bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
1742 NamedDecl *PrevMemberDecl,
1743 AccessSpecifier LexicalAS);
1744
1745 bool CheckBaseClassAccess(QualType Derived, QualType Base,
1746 BasePaths& Paths, SourceLocation AccessLoc);
1747
1748
Anders Carlsson412c3402009-03-24 01:19:16 +00001749 enum AbstractDiagSelID {
1750 AbstractNone = -1,
1751 AbstractReturnType,
1752 AbstractParamType,
1753 AbstractVariableType,
1754 AbstractFieldType
1755 };
1756
1757 bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID,
Anders Carlssonde9e7892009-03-24 17:23:42 +00001758 AbstractDiagSelID SelID = AbstractNone,
1759 const CXXRecordDecl *CurrentRD = 0);
Anders Carlssone1299b32009-03-22 20:18:17 +00001760
Douglas Gregore60e5d32008-11-06 22:13:31 +00001761 //===--------------------------------------------------------------------===//
1762 // C++ Overloaded Operators [C++ 13.5]
1763 //
1764
1765 bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl);
1766
Douglas Gregordd861062008-12-05 18:15:24 +00001767 //===--------------------------------------------------------------------===//
1768 // C++ Templates [C++ 14]
1769 //
Douglas Gregoraabb8502009-03-31 00:43:58 +00001770 virtual TemplateNameKind isTemplateName(const IdentifierInfo &II, Scope *S,
Douglas Gregordd13e842009-03-30 22:58:21 +00001771 TemplateTy &Template,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001772 const CXXScopeSpec *SS = 0);
Douglas Gregordd861062008-12-05 18:15:24 +00001773 bool DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
Chris Lattner5261d0c2009-03-28 19:18:32 +00001774 TemplateDecl *AdjustDeclIfTemplate(DeclPtrTy &Decl);
Douglas Gregor279272e2009-02-04 19:02:06 +00001775
Chris Lattner5261d0c2009-03-28 19:18:32 +00001776 virtual DeclPtrTy ActOnTypeParameter(Scope *S, bool Typename,
1777 SourceLocation KeyLoc,
1778 IdentifierInfo *ParamName,
1779 SourceLocation ParamNameLoc,
1780 unsigned Depth, unsigned Position);
1781 virtual void ActOnTypeParameterDefault(DeclPtrTy TypeParam,
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001782 SourceLocation EqualLoc,
1783 SourceLocation DefaultLoc,
1784 TypeTy *Default);
1785
Douglas Gregored3a3982009-03-03 04:44:36 +00001786 QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc);
Chris Lattner5261d0c2009-03-28 19:18:32 +00001787 virtual DeclPtrTy ActOnNonTypeTemplateParameter(Scope *S, Declarator &D,
1788 unsigned Depth,
1789 unsigned Position);
1790 virtual void ActOnNonTypeTemplateParameterDefault(DeclPtrTy TemplateParam,
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001791 SourceLocation EqualLoc,
1792 ExprArg Default);
Chris Lattner5261d0c2009-03-28 19:18:32 +00001793 virtual DeclPtrTy ActOnTemplateTemplateParameter(Scope *S,
1794 SourceLocation TmpLoc,
1795 TemplateParamsTy *Params,
1796 IdentifierInfo *ParamName,
1797 SourceLocation ParamNameLoc,
1798 unsigned Depth,
1799 unsigned Position);
1800 virtual void ActOnTemplateTemplateParameterDefault(DeclPtrTy TemplateParam,
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001801 SourceLocation EqualLoc,
1802 ExprArg Default);
1803
Douglas Gregor52473432008-12-24 02:52:09 +00001804 virtual TemplateParamsTy *
1805 ActOnTemplateParameterList(unsigned Depth,
1806 SourceLocation ExportLoc,
1807 SourceLocation TemplateLoc,
1808 SourceLocation LAngleLoc,
Chris Lattner5261d0c2009-03-28 19:18:32 +00001809 DeclPtrTy *Params, unsigned NumParams,
Douglas Gregor52473432008-12-24 02:52:09 +00001810 SourceLocation RAngleLoc);
Douglas Gregor9225a7e2009-02-10 19:49:53 +00001811 bool CheckTemplateParameterList(TemplateParameterList *NewParams,
1812 TemplateParameterList *OldParams);
1813
Douglas Gregorc5d6fa72009-03-25 00:13:59 +00001814 virtual DeclResult
Douglas Gregord406b032009-02-06 22:42:48 +00001815 ActOnClassTemplate(Scope *S, unsigned TagSpec, TagKind TK,
1816 SourceLocation KWLoc, const CXXScopeSpec &SS,
1817 IdentifierInfo *Name, SourceLocation NameLoc,
1818 AttributeList *Attr,
Anders Carlssoned20fb92009-03-26 00:52:18 +00001819 MultiTemplateParamsArg TemplateParameterLists,
1820 AccessSpecifier AS);
Douglas Gregord406b032009-02-06 22:42:48 +00001821
Douglas Gregordd13e842009-03-30 22:58:21 +00001822 QualType CheckTemplateIdType(TemplateName Template,
1823 SourceLocation TemplateLoc,
1824 SourceLocation LAngleLoc,
1825 const TemplateArgument *TemplateArgs,
1826 unsigned NumTemplateArgs,
1827 SourceLocation RAngleLoc);
Douglas Gregorf9ff4b12009-03-09 23:48:35 +00001828
Douglas Gregora08b6c72009-02-17 23:15:12 +00001829 virtual TypeResult
Douglas Gregordd13e842009-03-30 22:58:21 +00001830 ActOnTemplateIdType(TemplateTy Template, SourceLocation TemplateLoc,
1831 SourceLocation LAngleLoc,
1832 ASTTemplateArgsPtr TemplateArgs,
1833 SourceLocation *TemplateArgLocs,
1834 SourceLocation RAngleLoc);
Douglas Gregora08b6c72009-02-17 23:15:12 +00001835
Douglas Gregoraabb8502009-03-31 00:43:58 +00001836 virtual TemplateTy ActOnDependentTemplateName(SourceLocation TemplateKWLoc,
1837 const IdentifierInfo &Name,
1838 SourceLocation NameLoc,
1839 const CXXScopeSpec &SS);
1840
Douglas Gregor0d93f692009-02-25 22:02:03 +00001841 bool CheckClassTemplateSpecializationScope(ClassTemplateDecl *ClassTemplate,
1842 ClassTemplateSpecializationDecl *PrevDecl,
1843 SourceLocation TemplateNameLoc,
1844 SourceRange ScopeSpecifierRange);
1845
Douglas Gregorc5d6fa72009-03-25 00:13:59 +00001846 virtual DeclResult
Douglas Gregora08b6c72009-02-17 23:15:12 +00001847 ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
1848 SourceLocation KWLoc,
1849 const CXXScopeSpec &SS,
Douglas Gregordd13e842009-03-30 22:58:21 +00001850 TemplateTy Template,
Douglas Gregora08b6c72009-02-17 23:15:12 +00001851 SourceLocation TemplateNameLoc,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001852 SourceLocation LAngleLoc,
Douglas Gregor6f37b582009-02-09 19:34:22 +00001853 ASTTemplateArgsPtr TemplateArgs,
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001854 SourceLocation *TemplateArgLocs,
Douglas Gregor8e458f42009-02-09 18:46:07 +00001855 SourceLocation RAngleLoc,
Douglas Gregora08b6c72009-02-17 23:15:12 +00001856 AttributeList *Attr,
1857 MultiTemplateParamsArg TemplateParameterLists);
Douglas Gregor8e458f42009-02-09 18:46:07 +00001858
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001859 bool CheckTemplateArgumentList(TemplateDecl *Template,
1860 SourceLocation TemplateLoc,
1861 SourceLocation LAngleLoc,
Douglas Gregorf9ff4b12009-03-09 23:48:35 +00001862 const TemplateArgument *TemplateArgs,
1863 unsigned NumTemplateArgs,
Douglas Gregorad964b32009-02-17 01:05:43 +00001864 SourceLocation RAngleLoc,
1865 llvm::SmallVectorImpl<TemplateArgument> &Converted);
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001866
1867 bool CheckTemplateArgument(TemplateTypeParmDecl *Param, QualType Arg,
1868 SourceLocation ArgLoc);
Douglas Gregorad964b32009-02-17 01:05:43 +00001869 bool CheckTemplateArgumentAddressOfObjectOrFunction(Expr *Arg,
1870 NamedDecl *&Entity);
1871 bool CheckTemplateArgumentPointerToMember(Expr *Arg, NamedDecl *&Member);
Douglas Gregored3a3982009-03-03 04:44:36 +00001872 bool CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
1873 QualType InstantiatedParamType, Expr *&Arg,
Douglas Gregorad964b32009-02-17 01:05:43 +00001874 llvm::SmallVectorImpl<TemplateArgument> *Converted = 0);
Douglas Gregor35d81bb2009-02-09 23:23:08 +00001875 bool CheckTemplateArgument(TemplateTemplateParmDecl *Param, DeclRefExpr *Arg);
Douglas Gregord406b032009-02-06 22:42:48 +00001876 bool TemplateParameterListsAreEqual(TemplateParameterList *New,
1877 TemplateParameterList *Old,
1878 bool Complain,
Douglas Gregore8e367f2009-02-10 00:24:35 +00001879 bool IsTemplateTemplateParm = false,
1880 SourceLocation TemplateArgLoc
1881 = SourceLocation());
Douglas Gregord406b032009-02-06 22:42:48 +00001882
1883 bool CheckTemplateDeclScope(Scope *S,
1884 MultiTemplateParamsArg &TemplateParameterLists);
Douglas Gregor279272e2009-02-04 19:02:06 +00001885
Douglas Gregord3022602009-03-27 23:10:48 +00001886 /// \brief Called when the parser has parsed a C++ typename
1887 /// specifier, e.g., "typename T::type".
1888 ///
1889 /// \param TypenameLoc the location of the 'typename' keyword
1890 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
1891 /// \param II the identifier we're retrieving (e.g., 'type' in the example).
1892 /// \param IdLoc the location of the identifier.
1893 virtual TypeResult
1894 ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,
1895 const IdentifierInfo &II, SourceLocation IdLoc);
Douglas Gregor77da5802009-04-01 00:28:59 +00001896
1897 /// \brief Called when the parser has parsed a C++ typename
1898 /// specifier that ends in a template-id, e.g.,
1899 /// "typename MetaFun::template apply<T1, T2>".
1900 ///
1901 /// \param TypenameLoc the location of the 'typename' keyword
1902 /// \param SS the nested-name-specifier following the typename (e.g., 'T::').
1903 /// \param TemplateLoc the location of the 'template' keyword, if any.
1904 /// \param Ty the type that the typename specifier refers to.
1905 virtual TypeResult
1906 ActOnTypenameType(SourceLocation TypenameLoc, const CXXScopeSpec &SS,
1907 SourceLocation TemplateLoc, TypeTy *Ty);
1908
Douglas Gregord3022602009-03-27 23:10:48 +00001909 QualType CheckTypenameType(NestedNameSpecifier *NNS,
1910 const IdentifierInfo &II,
1911 SourceRange Range);
1912
Douglas Gregor74296542009-02-27 19:31:52 +00001913 //===--------------------------------------------------------------------===//
1914 // C++ Template Instantiation
1915 //
Douglas Gregor375733c2009-03-10 00:06:19 +00001916
1917 /// \brief A template instantiation that is currently in progress.
1918 struct ActiveTemplateInstantiation {
Douglas Gregor56d25a72009-03-10 20:44:00 +00001919 /// \brief The kind of template instantiation we are performing
1920 enum {
1921 /// We are instantiating a template declaration. The entity is
Douglas Gregorcc887972009-03-25 21:17:03 +00001922 /// the declaration we're instantiation (e.g., a CXXRecordDecl).
Douglas Gregor56d25a72009-03-10 20:44:00 +00001923 TemplateInstantiation,
1924
1925 /// We are instantiating a default argument for a template
1926 /// parameter. The Entity is the template, and
1927 /// TemplateArgs/NumTemplateArguments provides the template
1928 /// arguments as specified.
1929 DefaultTemplateArgumentInstantiation
1930 } Kind;
1931
Douglas Gregor375733c2009-03-10 00:06:19 +00001932 /// \brief The point of instantiation within the source code.
1933 SourceLocation PointOfInstantiation;
1934
1935 /// \brief The entity that is being instantiated.
Douglas Gregor56d25a72009-03-10 20:44:00 +00001936 uintptr_t Entity;
1937
1938 // \brief If this the instantiation of a default template
1939 // argument, the list of tempalte arguments.
1940 const TemplateArgument *TemplateArgs;
1941
1942 /// \brief The number of template arguments in TemplateArgs.
1943 unsigned NumTemplateArgs;
Douglas Gregor375733c2009-03-10 00:06:19 +00001944
1945 /// \brief The source range that covers the construct that cause
1946 /// the instantiation, e.g., the template-id that causes a class
1947 /// template instantiation.
1948 SourceRange InstantiationRange;
Douglas Gregor56d25a72009-03-10 20:44:00 +00001949
1950 friend bool operator==(const ActiveTemplateInstantiation &X,
1951 const ActiveTemplateInstantiation &Y) {
1952 if (X.Kind != Y.Kind)
1953 return false;
1954
1955 if (X.Entity != Y.Entity)
1956 return false;
1957
1958 switch (X.Kind) {
1959 case TemplateInstantiation:
1960 return true;
1961
1962 case DefaultTemplateArgumentInstantiation:
1963 return X.TemplateArgs == Y.TemplateArgs;
1964 }
1965
1966 return true;
1967 }
1968
1969 friend bool operator!=(const ActiveTemplateInstantiation &X,
1970 const ActiveTemplateInstantiation &Y) {
1971 return !(X == Y);
1972 }
Douglas Gregor375733c2009-03-10 00:06:19 +00001973 };
1974
1975 /// \brief List of active template instantiations.
1976 ///
1977 /// This vector is treated as a stack. As one template instantiation
1978 /// requires another template instantiation, additional
1979 /// instantiations are pushed onto the stack up to a
1980 /// user-configurable limit LangOptions::InstantiationDepth.
1981 llvm::SmallVector<ActiveTemplateInstantiation, 16>
1982 ActiveTemplateInstantiations;
1983
Douglas Gregord9572a12009-03-10 18:52:44 +00001984 /// \brief The last template from which a template instantiation
1985 /// error or warning was produced.
1986 ///
1987 /// This value is used to suppress printing of redundant template
1988 /// instantiation backtraces when there are multiple errors in the
1989 /// same instantiation. FIXME: Does this belong in Sema? It's tough
1990 /// to implement it anywhere else.
Douglas Gregor56d25a72009-03-10 20:44:00 +00001991 ActiveTemplateInstantiation LastTemplateInstantiationErrorContext;
Douglas Gregord9572a12009-03-10 18:52:44 +00001992
Douglas Gregor375733c2009-03-10 00:06:19 +00001993 /// \brief A stack object to be created when performing template
1994 /// instantiation.
1995 ///
1996 /// Construction of an object of type \c InstantiatingTemplate
1997 /// pushes the current instantiation onto the stack of active
1998 /// instantiations. If the size of this stack exceeds the maximum
1999 /// number of recursive template instantiations, construction
2000 /// produces an error and evaluates true.
2001 ///
2002 /// Destruction of this object will pop the named instantiation off
2003 /// the stack.
2004 struct InstantiatingTemplate {
Douglas Gregor56d25a72009-03-10 20:44:00 +00002005 /// \brief Note that we are instantiating a class template.
Douglas Gregor375733c2009-03-10 00:06:19 +00002006 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
Douglas Gregorcc887972009-03-25 21:17:03 +00002007 CXXRecordDecl *Entity,
Douglas Gregor375733c2009-03-10 00:06:19 +00002008 SourceRange InstantiationRange = SourceRange());
Douglas Gregor56d25a72009-03-10 20:44:00 +00002009
2010 /// \brief Note that we are instantiating a default argument in a
2011 /// template-id.
2012 InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation,
2013 TemplateDecl *Template,
2014 const TemplateArgument *TemplateArgs,
2015 unsigned NumTemplateArgs,
2016 SourceRange InstantiationRange = SourceRange());
2017
Douglas Gregor375733c2009-03-10 00:06:19 +00002018 ~InstantiatingTemplate();
2019
2020 /// \brief Determines whether we have exceeded the maximum
2021 /// recursive template instantiations.
2022 operator bool() const { return Invalid; }
2023
2024 private:
2025 Sema &SemaRef;
2026 bool Invalid;
2027
Douglas Gregor56d25a72009-03-10 20:44:00 +00002028 bool CheckInstantiationDepth(SourceLocation PointOfInstantiation,
2029 SourceRange InstantiationRange);
2030
Douglas Gregor375733c2009-03-10 00:06:19 +00002031 InstantiatingTemplate(const InstantiatingTemplate&); // not implemented
2032
2033 InstantiatingTemplate&
2034 operator=(const InstantiatingTemplate&); // not implemented
2035 };
2036
Douglas Gregorfee85d62009-03-10 18:03:33 +00002037 void PrintInstantiationStack();
2038
Douglas Gregor74296542009-02-27 19:31:52 +00002039 QualType InstantiateType(QualType T, const TemplateArgument *TemplateArgs,
2040 unsigned NumTemplateArgs,
2041 SourceLocation Loc, DeclarationName Entity);
Douglas Gregorbd300312009-03-12 16:53:44 +00002042
2043 OwningExprResult InstantiateExpr(Expr *E,
2044 const TemplateArgument *TemplateArgs,
2045 unsigned NumTemplateArgs);
2046
Douglas Gregor1b39ef42009-03-17 21:15:40 +00002047 Decl *InstantiateDecl(Decl *D, DeclContext *Owner,
2048 const TemplateArgument *TemplateArgs,
2049 unsigned NumTemplateArgs);
2050
Douglas Gregored3a3982009-03-03 04:44:36 +00002051 bool
Douglas Gregorcc887972009-03-25 21:17:03 +00002052 InstantiateBaseSpecifiers(CXXRecordDecl *Instantiation,
2053 CXXRecordDecl *Pattern,
2054 const TemplateArgument *TemplateArgs,
2055 unsigned NumTemplateArgs);
2056
2057 bool
2058 InstantiateClass(SourceLocation PointOfInstantiation,
2059 CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern,
2060 const TemplateArgument *TemplateArgs,
2061 unsigned NumTemplateArgs);
2062
Douglas Gregored3a3982009-03-03 04:44:36 +00002063 bool
2064 InstantiateClassTemplateSpecialization(
2065 ClassTemplateSpecializationDecl *ClassTemplateSpec,
2066 bool ExplicitInstantiation);
Douglas Gregor74296542009-02-27 19:31:52 +00002067
Douglas Gregor1e589cc2009-03-26 23:50:42 +00002068 NestedNameSpecifier *
2069 InstantiateNestedNameSpecifier(NestedNameSpecifier *NNS,
2070 SourceRange Range,
2071 const TemplateArgument *TemplateArgs,
2072 unsigned NumTemplateArgs);
Douglas Gregor47bde7c2009-03-19 17:26:29 +00002073
Douglas Gregor15a92852009-03-31 18:38:02 +00002074 TemplateName
2075 InstantiateTemplateName(TemplateName Name, SourceLocation Loc,
2076 const TemplateArgument *TemplateArgs,
2077 unsigned NumTemplateArgs);
2078
Anders Carlsson7f2e7442009-03-15 18:34:13 +00002079 // Simple function for cloning expressions.
2080 template<typename T>
2081 OwningExprResult Clone(T *E) {
2082 assert(!E->isValueDependent() && !E->isTypeDependent() &&
2083 "expression is value or type dependent!");
2084 return Owned(E->Clone(Context));
2085 }
2086
Steve Naroff81f1bba2007-09-06 21:24:23 +00002087 // Objective-C declarations.
Chris Lattner5261d0c2009-03-28 19:18:32 +00002088 virtual DeclPtrTy ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
2089 IdentifierInfo *ClassName,
2090 SourceLocation ClassLoc,
2091 IdentifierInfo *SuperName,
2092 SourceLocation SuperLoc,
2093 const DeclPtrTy *ProtoRefs,
2094 unsigned NumProtoRefs,
2095 SourceLocation EndProtoLoc,
2096 AttributeList *AttrList);
Fariborz Jahanian05d212a2007-10-11 23:42:27 +00002097
Chris Lattner5261d0c2009-03-28 19:18:32 +00002098 virtual DeclPtrTy ActOnCompatiblityAlias(
Fariborz Jahanian05d212a2007-10-11 23:42:27 +00002099 SourceLocation AtCompatibilityAliasLoc,
2100 IdentifierInfo *AliasName, SourceLocation AliasLocation,
2101 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Narofffe56a632009-03-05 15:22:01 +00002102
2103 void CheckForwardProtocolDeclarationForCircularDependency(
2104 IdentifierInfo *PName,
2105 SourceLocation &PLoc, SourceLocation PrevLoc,
2106 const ObjCList<ObjCProtocolDecl> &PList);
Steve Naroff81f1bba2007-09-06 21:24:23 +00002107
Chris Lattner5261d0c2009-03-28 19:18:32 +00002108 virtual DeclPtrTy ActOnStartProtocolInterface(
Nate Begeman43f307d2008-02-20 22:57:40 +00002109 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00002110 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner5261d0c2009-03-28 19:18:32 +00002111 const DeclPtrTy *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar28680d12008-09-26 04:48:09 +00002112 SourceLocation EndProtoLoc,
2113 AttributeList *AttrList);
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +00002114
Chris Lattner5261d0c2009-03-28 19:18:32 +00002115 virtual DeclPtrTy ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
2116 IdentifierInfo *ClassName,
2117 SourceLocation ClassLoc,
2118 IdentifierInfo *CategoryName,
2119 SourceLocation CategoryLoc,
2120 const DeclPtrTy *ProtoRefs,
2121 unsigned NumProtoRefs,
2122 SourceLocation EndProtoLoc);
Fariborz Jahanianf25220e2007-09-18 20:26:58 +00002123
Chris Lattner5261d0c2009-03-28 19:18:32 +00002124 virtual DeclPtrTy ActOnStartClassImplementation(
Nate Begeman43f307d2008-02-20 22:57:40 +00002125 SourceLocation AtClassImplLoc,
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +00002126 IdentifierInfo *ClassName, SourceLocation ClassLoc,
2127 IdentifierInfo *SuperClassname,
2128 SourceLocation SuperClassLoc);
2129
Chris Lattner5261d0c2009-03-28 19:18:32 +00002130 virtual DeclPtrTy ActOnStartCategoryImplementation(
Fariborz Jahaniana91aa322007-10-02 16:38:50 +00002131 SourceLocation AtCatImplLoc,
2132 IdentifierInfo *ClassName,
2133 SourceLocation ClassLoc,
2134 IdentifierInfo *CatName,
2135 SourceLocation CatLoc);
2136
Chris Lattner5261d0c2009-03-28 19:18:32 +00002137 virtual DeclPtrTy ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroffb4dfe362007-10-02 22:39:18 +00002138 IdentifierInfo **IdentList,
2139 unsigned NumElts);
Fariborz Jahanianc716c942007-09-21 15:40:54 +00002140
Chris Lattner5261d0c2009-03-28 19:18:32 +00002141 virtual DeclPtrTy ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnere705e5e2008-07-21 22:17:28 +00002142 const IdentifierLocPair *IdentList,
Fariborz Jahanian8f9b1b22008-12-17 01:07:27 +00002143 unsigned NumElts,
2144 AttributeList *attrList);
Fariborz Jahaniana096e1d2007-10-05 21:01:53 +00002145
Chris Lattner2bdedd62008-07-26 04:03:38 +00002146 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnere705e5e2008-07-21 22:17:28 +00002147 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian91193f62007-10-11 00:55:41 +00002148 unsigned NumProtocols,
Chris Lattner5261d0c2009-03-28 19:18:32 +00002149 llvm::SmallVectorImpl<DeclPtrTy> &Protocols);
Fariborz Jahanianed986602008-05-01 00:03:38 +00002150
Daniel Dunbar540ff472008-09-23 21:53:23 +00002151 /// Ensure attributes are consistent with type.
2152 /// \param [in, out] Attributes The attributes to check; they will
2153 /// be modified to be consistent with \arg PropertyTy.
2154 void CheckObjCPropertyAttributes(QualType PropertyTy,
2155 SourceLocation Loc,
2156 unsigned &Attributes);
Steve Naroffab63fd62009-01-08 17:28:14 +00002157 void ProcessPropertyDecl(ObjCPropertyDecl *property, ObjCContainerDecl *DC);
Fariborz Jahanianed986602008-05-01 00:03:38 +00002158 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
2159 ObjCPropertyDecl *SuperProperty,
Chris Lattnerd120b9e2008-11-24 03:54:41 +00002160 const IdentifierInfo *Name);
Fariborz Jahanianed986602008-05-01 00:03:38 +00002161 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian1e89de32008-04-24 19:58:34 +00002162
Fariborz Jahanianacad6d12008-12-06 23:03:39 +00002163 void MergeProtocolPropertiesIntoClass(Decl *CDecl,
Chris Lattner5261d0c2009-03-28 19:18:32 +00002164 DeclPtrTy MergeProtocols);
Fariborz Jahanian33973a22008-05-02 19:17:30 +00002165
Fariborz Jahanianffb68822009-03-02 19:05:07 +00002166 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
2167 ObjCInterfaceDecl *ID);
2168
Fariborz Jahanianacad6d12008-12-06 23:03:39 +00002169 void MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
Fariborz Jahanian33973a22008-05-02 19:17:30 +00002170 ObjCProtocolDecl *PDecl);
2171
Chris Lattner5261d0c2009-03-28 19:18:32 +00002172 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclPtrTy classDecl,
2173 DeclPtrTy *allMethods = 0, unsigned allNum = 0,
2174 DeclPtrTy *allProperties = 0, unsigned pNum = 0,
Chris Lattnera17991f2009-03-29 16:50:03 +00002175 DeclGroupPtrTy *allTUVars = 0, unsigned tuvNum = 0);
Fariborz Jahaniand34caf92007-09-26 18:27:25 +00002176
Chris Lattner5261d0c2009-03-28 19:18:32 +00002177 virtual DeclPtrTy ActOnProperty(Scope *S, SourceLocation AtLoc,
2178 FieldDeclarator &FD, ObjCDeclSpec &ODS,
2179 Selector GetterSel, Selector SetterSel,
2180 DeclPtrTy ClassCategory,
2181 bool *OverridingProperty,
2182 tok::ObjCKeywordKind MethodImplKind);
Fariborz Jahanian4aa72a72008-05-05 18:51:55 +00002183
Chris Lattner5261d0c2009-03-28 19:18:32 +00002184 virtual DeclPtrTy ActOnPropertyImplDecl(SourceLocation AtLoc,
2185 SourceLocation PropertyLoc,
2186 bool ImplKind,DeclPtrTy ClassImplDecl,
2187 IdentifierInfo *PropertyId,
2188 IdentifierInfo *PropertyIvar);
Fariborz Jahanian78f7e312008-04-18 00:19:30 +00002189
Chris Lattner5261d0c2009-03-28 19:18:32 +00002190 virtual DeclPtrTy ActOnMethodDeclaration(
Steve Naroff3774dd92007-10-26 20:53:56 +00002191 SourceLocation BeginLoc, // location of the + or -.
2192 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian8473b222007-11-09 19:52:12 +00002193 tok::TokenKind MethodType,
Chris Lattner5261d0c2009-03-28 19:18:32 +00002194 DeclPtrTy ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian2fd0daa2007-10-31 23:53:01 +00002195 Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +00002196 // optional arguments. The number of types/arguments is obtained
2197 // from the Sel.getNumArgs().
Chris Lattner612a2f72009-04-11 18:57:04 +00002198 ObjCArgInfo *ArgInfo,
Fariborz Jahanian89d53042009-01-09 00:38:19 +00002199 llvm::SmallVectorImpl<Declarator> &Cdecls,
Steve Naroff29fe7462007-11-15 12:35:21 +00002200 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
2201 bool isVariadic = false);
Steve Naroff52664182007-10-16 23:12:48 +00002202
Steve Naroff4b129152009-02-26 15:55:06 +00002203 // Helper method for ActOnClassMethod/ActOnInstanceMethod.
2204 // Will search "local" class/category implementations for a method decl.
Fariborz Jahanian271f9062009-03-04 18:15:57 +00002205 // Will also search in class's root looking for instance method.
Steve Naroff4b129152009-02-26 15:55:06 +00002206 // Returns 0 if no method is found.
Steve Naroff9d8dc2b2009-03-08 18:56:13 +00002207 ObjCMethodDecl *LookupPrivateClassMethod(Selector Sel,
2208 ObjCInterfaceDecl *CDecl);
2209 ObjCMethodDecl *LookupPrivateInstanceMethod(Selector Sel,
2210 ObjCInterfaceDecl *ClassDecl);
Steve Naroff4b129152009-02-26 15:55:06 +00002211
Steve Naroff73ec9322009-03-09 21:12:44 +00002212 virtual OwningExprResult ActOnClassPropertyRefExpr(
2213 IdentifierInfo &receiverName,
2214 IdentifierInfo &propertyName,
2215 SourceLocation &receiverNameLoc,
2216 SourceLocation &propertyNameLoc);
2217
Steve Naroff4ed9d662007-09-27 14:38:14 +00002218 // ActOnClassMessage - used for both unary and keyword messages.
2219 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff9f176d12007-11-15 13:05:42 +00002220 // is obtained from NumArgs.
Steve Naroff4ed9d662007-09-27 14:38:14 +00002221 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian2ce5dc52007-11-12 20:13:27 +00002222 Scope *S,
Anders Carlssonb42900d2009-02-14 18:21:46 +00002223 IdentifierInfo *receivingClassName, Selector Sel, SourceLocation lbrac,
2224 SourceLocation receiverLoc, SourceLocation selectorLoc,SourceLocation rbrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00002225 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff4ed9d662007-09-27 14:38:14 +00002226
2227 // ActOnInstanceMessage - used for both unary and keyword messages.
2228 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff9f176d12007-11-15 13:05:42 +00002229 // is obtained from NumArgs.
Steve Naroff4ed9d662007-09-27 14:38:14 +00002230 virtual ExprResult ActOnInstanceMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +00002231 ExprTy *receiver, Selector Sel,
Anders Carlssonb42900d2009-02-14 18:21:46 +00002232 SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00002233 ExprTy **ArgExprs, unsigned NumArgs);
Daniel Dunbar81c7d472008-10-14 05:35:18 +00002234
2235 /// ActOnPragmaPack - Called on well formed #pragma pack(...).
2236 virtual void ActOnPragmaPack(PragmaPackKind Kind,
2237 IdentifierInfo *Name,
2238 ExprTy *Alignment,
2239 SourceLocation PragmaLoc,
2240 SourceLocation LParenLoc,
2241 SourceLocation RParenLoc);
Chris Lattnera8699562009-02-17 01:09:29 +00002242
Ted Kremenek86a631b2009-03-23 22:28:25 +00002243 /// ActOnPragmaUnused - Called on well-formed '#pragma unused'.
2244 virtual void ActOnPragmaUnused(ExprTy **Exprs, unsigned NumExprs,
2245 SourceLocation PragmaLoc,
2246 SourceLocation LParenLoc,
2247 SourceLocation RParenLoc);
2248
Chris Lattnera8699562009-02-17 01:09:29 +00002249 /// getPragmaPackAlignment() - Return the current alignment as specified by
2250 /// the current #pragma pack directive, or 0 if none is currently active.
2251 unsigned getPragmaPackAlignment() const;
2252
2253 /// FreePackedContext - Deallocate and null out PackContext.
2254 void FreePackedContext();
Daniel Dunbar81c7d472008-10-14 05:35:18 +00002255
Chris Lattnere992d6c2008-01-16 19:17:22 +00002256 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
2257 /// cast. If there is already an implicit cast, merge into the existing one.
Douglas Gregor70d26122008-11-12 17:17:38 +00002258 /// If isLvalue, the result of the cast is an lvalue.
2259 void ImpCastExprToType(Expr *&Expr, QualType Type, bool isLvalue = false);
Chris Lattnere992d6c2008-01-16 19:17:22 +00002260
Chris Lattner4b009652007-07-25 00:24:17 +00002261 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002262 // functions and arrays to their respective pointers (C99 6.3.2.1).
2263 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman86ad5222008-05-27 03:33:27 +00002264
Chris Lattner4b009652007-07-25 00:24:17 +00002265 // DefaultFunctionArrayConversion - converts functions and arrays
2266 // to their respective pointers (C99 6.3.2.1).
2267 void DefaultFunctionArrayConversion(Expr *&expr);
2268
Steve Naroffdb65e052007-08-28 23:30:39 +00002269 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
2270 // do not have a prototype. Integer promotions are performed on each
2271 // argument, and arguments that have type float are promoted to double.
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002272 void DefaultArgumentPromotion(Expr *&Expr);
Anders Carlsson4b8e38c2009-01-16 16:48:51 +00002273
2274 // Used for emitting the right warning by DefaultVariadicArgumentPromotion
2275 enum VariadicCallType {
2276 VariadicFunction,
2277 VariadicBlock,
2278 VariadicMethod
2279 };
2280
2281 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
2282 // will warn if the resulting type is not a POD type.
Chris Lattner81f00ed2009-04-12 08:11:20 +00002283 bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
Steve Naroffdb65e052007-08-28 23:30:39 +00002284
Chris Lattner4b009652007-07-25 00:24:17 +00002285 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
2286 // operands and then handles various conversions that are common to binary
2287 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
2288 // routine returns the first non-arithmetic type found. The client is
2289 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +00002290 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
2291 bool isCompAssign = false);
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002292
Douglas Gregor70d26122008-11-12 17:17:38 +00002293 /// UsualArithmeticConversionsType - handles the various conversions
2294 /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
2295 /// and returns the result type of that conversion.
2296 QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
2297
2298
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002299 /// AssignConvertType - All of the 'assignment' semantic checks return this
2300 /// enum to indicate whether the assignment was allowed. These checks are
2301 /// done for simple assignments, as well as initialization, return from
2302 /// function, argument passing, etc. The query is phrased in terms of a
2303 /// source and destination type.
Chris Lattner005ed752008-01-04 18:04:52 +00002304 enum AssignConvertType {
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002305 /// Compatible - the types are compatible according to the standard.
Chris Lattner4b009652007-07-25 00:24:17 +00002306 Compatible,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002307
2308 /// PointerToInt - The assignment converts a pointer to an int, which we
2309 /// accept as an extension.
2310 PointerToInt,
2311
2312 /// IntToPointer - The assignment converts an int to a pointer, which we
2313 /// accept as an extension.
2314 IntToPointer,
2315
2316 /// FunctionVoidPointer - The assignment is between a function pointer and
2317 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner4ca3d772008-01-03 22:56:36 +00002318 FunctionVoidPointer,
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002319
2320 /// IncompatiblePointer - The assignment is between two pointers types that
2321 /// are not compatible, but we accept them as an extension.
Chris Lattner4b009652007-07-25 00:24:17 +00002322 IncompatiblePointer,
Eli Friedman6ca28cb2009-03-22 23:59:44 +00002323
2324 /// IncompatiblePointer - The assignment is between two pointers types which
2325 /// point to integers which have a different sign, but are otherwise identical.
2326 /// This is a subset of the above, but broken out because it's by far the most
2327 /// common case of incompatible pointers.
2328 IncompatiblePointerSign,
2329
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002330 /// CompatiblePointerDiscardsQualifiers - The assignment discards
2331 /// c/v/r qualifiers, which we accept as an extension.
2332 CompatiblePointerDiscardsQualifiers,
Steve Naroff3454b6c2008-09-04 15:10:53 +00002333
Anders Carlsson355ed052009-01-30 23:17:46 +00002334 /// IncompatibleVectors - The assignment is between two vector types that
2335 /// have the same size, which we accept as an extension.
2336 IncompatibleVectors,
2337
Steve Naroff6f373332008-09-04 15:31:07 +00002338 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff3454b6c2008-09-04 15:10:53 +00002339 /// pointer. We disallow this.
2340 IntToBlockPointer,
2341
Steve Naroff6f373332008-09-04 15:31:07 +00002342 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff3454b6c2008-09-04 15:10:53 +00002343 /// pointers types that are not compatible.
2344 IncompatibleBlockPointer,
2345
Steve Naroff19608432008-10-14 22:18:38 +00002346 /// IncompatibleObjCQualifiedId - The assignment is between a qualified
2347 /// id type and something else (that is incompatible with it). For example,
2348 /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol.
2349 IncompatibleObjCQualifiedId,
2350
Chris Lattnerd951b7b2008-01-04 18:22:42 +00002351 /// Incompatible - We reject this conversion outright, it is invalid to
2352 /// represent it in the AST.
2353 Incompatible
Chris Lattner4b009652007-07-25 00:24:17 +00002354 };
Chris Lattner005ed752008-01-04 18:04:52 +00002355
2356 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
2357 /// assignment conversion type specified by ConvTy. This returns true if the
2358 /// conversion was invalid or false if the conversion was accepted.
2359 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
2360 SourceLocation Loc,
2361 QualType DstType, QualType SrcType,
2362 Expr *SrcExpr, const char *Flavor);
2363
2364 /// CheckAssignmentConstraints - Perform type checking for assignment,
2365 /// argument passing, variable initialization, and function return values.
2366 /// This routine is only used by the following two methods. C99 6.5.16.
2367 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Chris Lattner4b009652007-07-25 00:24:17 +00002368
Steve Naroff87d58b42007-09-16 03:34:24 +00002369 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff5cbb02f2007-09-16 14:56:35 +00002370 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Chris Lattner4b009652007-07-25 00:24:17 +00002371 // this routine performs the default function/array converions.
Chris Lattner005ed752008-01-04 18:04:52 +00002372 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
2373 Expr *&rExpr);
Chris Lattner4b009652007-07-25 00:24:17 +00002374 // CheckCompoundAssignmentConstraints - Type check without performing any
2375 // conversions. For compound assignments, the "Check...Operands" methods
2376 // perform the necessary conversions.
Chris Lattner005ed752008-01-04 18:04:52 +00002377 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
2378 QualType rhs);
Chris Lattner4b009652007-07-25 00:24:17 +00002379
2380 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner005ed752008-01-04 18:04:52 +00002381 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
2382 QualType rhsType);
Steve Naroff3454b6c2008-09-04 15:10:53 +00002383
2384 // Helper function for CheckAssignmentConstraints involving two
Sebastian Redl42b81a22009-04-19 19:26:31 +00002385 // block pointer types.
Steve Naroff3454b6c2008-09-04 15:10:53 +00002386 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
2387 QualType rhsType);
Douglas Gregor1815b3b2008-09-12 00:47:35 +00002388
2389 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Douglas Gregorbb461502008-10-24 04:54:22 +00002390
Douglas Gregor6fd35572008-12-19 17:40:08 +00002391 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Sebastian Redla55834a2009-04-12 17:16:29 +00002392 const char *Flavor,
2393 bool AllowExplicit = false,
2394 bool Elidable = false);
Douglas Gregor6214d8a2009-01-14 15:45:31 +00002395 bool PerformImplicitConversion(Expr *&From, QualType ToType,
2396 const ImplicitConversionSequence& ICS,
Douglas Gregor6fd35572008-12-19 17:40:08 +00002397 const char *Flavor);
Douglas Gregorbb461502008-10-24 04:54:22 +00002398 bool PerformImplicitConversion(Expr *&From, QualType ToType,
Douglas Gregor6fd35572008-12-19 17:40:08 +00002399 const StandardConversionSequence& SCS,
2400 const char *Flavor);
Sebastian Redl95216a62009-02-07 00:15:38 +00002401
Chris Lattner4b009652007-07-25 00:24:17 +00002402 /// the following "Check" methods will return a valid/converted QualType
2403 /// or a null QualType (indicating an error diagnostic was issued).
Sebastian Redl95216a62009-02-07 00:15:38 +00002404
2405 /// type checking binary operators (subroutines of CreateBuiltinBinOp).
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002406 QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Sebastian Redlaa4c3732009-02-07 20:10:22 +00002407 QualType CheckPointerToMemberOperands( // C++ 5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00002408 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isIndirect);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002409 QualType CheckMultiplyDivideOperands( // C99 6.5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00002410 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002411 QualType CheckRemainderOperands( // C99 6.5.5
Sebastian Redl95216a62009-02-07 00:15:38 +00002412 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002413 QualType CheckAdditionOperands( // C99 6.5.6
Eli Friedman3cd92882009-03-28 01:22:36 +00002414 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002415 QualType CheckSubtractionOperands( // C99 6.5.6
Eli Friedman3cd92882009-03-28 01:22:36 +00002416 Expr *&lex, Expr *&rex, SourceLocation OpLoc, QualType* CompLHSTy = 0);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002417 QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +00002418 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002419 QualType CheckCompareOperands( // C99 6.5.8/9
Douglas Gregor1f12c352009-04-06 18:45:53 +00002420 Expr *&lex, Expr *&rex, SourceLocation OpLoc, unsigned Opc, bool isRelational);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002421 QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Sebastian Redl95216a62009-02-07 00:15:38 +00002422 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002423 QualType CheckLogicalOperands( // C99 6.5.[13,14]
Chris Lattner4b009652007-07-25 00:24:17 +00002424 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
2425 // CheckAssignmentOperands is used for both simple and compound assignment.
2426 // For simple assignment, pass both expressions and a null converted type.
2427 // For compound assignment, pass both expressions and the converted type.
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002428 QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +00002429 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002430 QualType CheckCommaOperands( // C99 6.5.17
Chris Lattner1eafdea2008-11-18 01:30:42 +00002431 Expr *lex, Expr *&rex, SourceLocation OpLoc);
Douglas Gregor5b5b6692009-03-12 22:46:12 +00002432 QualType CheckConditionalOperands( // C99 6.5.15
Chris Lattner4b009652007-07-25 00:24:17 +00002433 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Sebastian Redlbd261962009-04-16 17:51:27 +00002434 QualType CXXCheckConditionalOperands( // C++ 5.16
2435 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Sebastian Redl42b81a22009-04-19 19:26:31 +00002436 QualType FindCompositePointerType(Expr *&E1, Expr *&E2); // C++ 5.9
Nate Begemanc5f0f652008-07-14 18:02:46 +00002437
2438 /// type checking for vector binary operators.
2439 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
2440 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
2441 SourceLocation l, bool isRel);
Chris Lattner4b009652007-07-25 00:24:17 +00002442
Steve Naroff87d58b42007-09-16 03:34:24 +00002443 /// type checking unary operators (subroutines of ActOnUnaryOp).
Chris Lattner4b009652007-07-25 00:24:17 +00002444 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Sebastian Redl0440c8c2008-12-20 09:35:34 +00002445 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc,
2446 bool isInc);
Chris Lattner4b009652007-07-25 00:24:17 +00002447 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
2448 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner57e5f7e2009-02-17 08:12:06 +00002449 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc, bool isReal);
Steve Naroff1b8a46c2007-07-27 22:15:19 +00002450
2451 /// type checking primary expressions.
Nate Begemanaf6ed502008-04-18 23:10:10 +00002452 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroff1b8a46c2007-07-27 22:15:19 +00002453 IdentifierInfo &Comp, SourceLocation CmpLoc);
2454
Steve Naroffe14e5542007-09-02 02:04:30 +00002455 /// type checking declaration initializers (C99 6.7.8)
Douglas Gregor6428e762008-11-05 15:29:30 +00002456 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00002457 SourceLocation InitLoc,DeclarationName InitEntity,
2458 bool DirectInit);
Douglas Gregor849afc32009-01-29 00:45:39 +00002459 bool CheckInitList(InitListExpr *&InitList, QualType &DeclType);
Steve Narofff0b23542008-01-10 22:15:12 +00002460 bool CheckForConstantInitializer(Expr *e, QualType t);
Steve Naroffcb69fb72007-12-10 22:44:33 +00002461
Douglas Gregor538a4c22009-02-02 17:43:21 +00002462 bool CheckValueInitialization(QualType Type, SourceLocation Loc);
Argiris Kirtzidis95de23a2008-08-16 20:27:34 +00002463
Douglas Gregor81c29152008-10-29 00:13:59 +00002464 // type checking C++ declaration initializers (C++ [dcl.init]).
2465
2466 /// ReferenceCompareResult - Expresses the result of comparing two
2467 /// types (cv1 T1 and cv2 T2) to determine their compatibility for the
2468 /// purposes of initialization by reference (C++ [dcl.init.ref]p4).
2469 enum ReferenceCompareResult {
2470 /// Ref_Incompatible - The two types are incompatible, so direct
2471 /// reference binding is not possible.
2472 Ref_Incompatible = 0,
2473 /// Ref_Related - The two types are reference-related, which means
2474 /// that their unqualified forms (T1 and T2) are either the same
2475 /// or T1 is a base class of T2.
2476 Ref_Related,
2477 /// Ref_Compatible_With_Added_Qualification - The two types are
2478 /// reference-compatible with added qualification, meaning that
2479 /// they are reference-compatible and the qualifiers on T1 (cv1)
2480 /// are greater than the qualifiers on T2 (cv2).
2481 Ref_Compatible_With_Added_Qualification,
2482 /// Ref_Compatible - The two types are reference-compatible and
2483 /// have equivalent qualifiers (cv1 == cv2).
2484 Ref_Compatible
2485 };
2486
Douglas Gregor2aecd1f2008-10-29 02:00:59 +00002487 ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
2488 bool& DerivedToBase);
Douglas Gregor81c29152008-10-29 00:13:59 +00002489
Sebastian Redlbd261962009-04-16 17:51:27 +00002490 bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType declType,
Douglas Gregora3b34bb2008-11-03 19:09:14 +00002491 ImplicitConversionSequence *ICS = 0,
Douglas Gregor6214d8a2009-01-14 15:45:31 +00002492 bool SuppressUserConversions = false,
Sebastian Redla55834a2009-04-12 17:16:29 +00002493 bool AllowExplicit = false,
2494 bool ForceRValue = false);
Douglas Gregor81c29152008-10-29 00:13:59 +00002495
Argiris Kirtzidis95de23a2008-08-16 20:27:34 +00002496 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar5ad49de2008-08-20 03:55:42 +00002497 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroff0d4e6ad2008-01-22 00:55:40 +00002498
Anders Carlsson74375622007-11-27 07:16:40 +00002499 // CheckVectorCast - check type constraints for vectors.
2500 // Since vectors are an extension, there are no C standard reference for this.
2501 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonf257b4c2007-11-27 05:51:55 +00002502 // returns true if the cast is invalid
2503 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
2504
Daniel Dunbar842b5e22008-09-11 00:01:56 +00002505 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
2506 /// \param Method - May be null.
2507 /// \param [out] ReturnType - The return type of the send.
2508 /// \return true iff there were any incompatible types.
Daniel Dunbar7776e102008-09-11 00:50:25 +00002509 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Chris Lattner3a8f2942008-11-24 03:33:13 +00002510 ObjCMethodDecl *Method, bool isClassMessage,
Daniel Dunbar842b5e22008-09-11 00:01:56 +00002511 SourceLocation lbrac, SourceLocation rbrac,
2512 QualType &ReturnType);
Argiris Kirtzidis810c0f72008-09-10 02:17:11 +00002513
2514 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
2515 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff52664182007-10-16 23:12:48 +00002516
Chris Lattner3429a812007-08-23 05:46:52 +00002517 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
2518 /// the specified width and sign. If an overflow occurs, detect it and emit
2519 /// the specified diagnostic.
2520 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
2521 unsigned NewWidth, bool NewSign,
2522 SourceLocation Loc, unsigned DiagID);
2523
Chris Lattnerfe1f4032008-04-07 05:30:13 +00002524 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
2525 bool ForCompare);
2526
Anders Carlsson0a6ab172008-11-04 16:57:32 +00002527 /// Checks that the Objective-C declaration is declared in the global scope.
2528 /// Emits an error and marks the declaration as invalid if it's not declared
2529 /// in the global scope.
2530 bool CheckObjCDeclScope(Decl *D);
2531
Anders Carlsson36760332007-10-15 20:28:48 +00002532 void InitBuiltinVaListType();
Eli Friedman48fb3ee2008-06-03 21:01:11 +00002533
Anders Carlssond5201b92008-11-30 19:50:32 +00002534 /// VerifyIntegerConstantExpression - verifies that an expression is an ICE,
2535 /// and reports the appropriate diagnostics. Returns false on success.
2536 /// Can optionally return the value of the expression.
Anders Carlsson108229a2008-12-06 20:33:04 +00002537 bool VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result = 0);
Anders Carlsson511425a2008-12-01 02:17:22 +00002538
Anders Carlsson108229a2008-12-06 20:33:04 +00002539 /// VerifyBitField - verifies that a bit field expression is an ICE and has
2540 /// the correct width, and that the field type is valid.
2541 /// Returns false on success.
2542 bool VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName,
2543 QualType FieldTy, const Expr *BitWidth);
Sebastian Redl8b769972009-01-19 00:08:26 +00002544
Chris Lattner2e64c072007-08-10 20:18:51 +00002545 //===--------------------------------------------------------------------===//
2546 // Extra semantic analysis beyond the C type system
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002547private:
Sebastian Redl8b769972009-01-19 00:08:26 +00002548 Action::OwningExprResult CheckFunctionCall(FunctionDecl *FDecl,
2549 CallExpr *TheCall);
Chris Lattnerf17cb362009-02-18 17:49:48 +00002550 SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL,
2551 unsigned ByteNo) const;
Chris Lattner81f5be22009-02-18 06:01:06 +00002552 bool CheckObjCString(Expr *Arg);
Chris Lattner83bd5eb2007-12-28 05:29:59 +00002553 bool SemaBuiltinVAStart(CallExpr *TheCall);
2554 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman8c50c622008-05-20 08:23:37 +00002555 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Sebastian Redl8b769972009-01-19 00:08:26 +00002556 Action::OwningExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar5b0de852008-07-21 22:59:13 +00002557 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbar30ad42d2008-09-03 21:13:56 +00002558 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Ted Kremenek51787c72009-03-20 21:35:28 +00002559 bool SemaCheckStringLiteral(const Expr *E, const CallExpr *TheCall,
2560 bool HasVAListArg, unsigned format_idx,
2561 unsigned firstDataArg);
2562 void CheckPrintfString(const StringLiteral *FExpr, const Expr *OrigFormatExpr,
2563 const CallExpr *TheCall, bool HasVAListArg,
Douglas Gregorb5af7382009-02-14 18:57:46 +00002564 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek51787c72009-03-20 21:35:28 +00002565 void CheckPrintfArguments(const CallExpr *TheCall, bool HasVAListArg,
Douglas Gregorb5af7382009-02-14 18:57:46 +00002566 unsigned format_idx, unsigned firstDataArg);
Ted Kremenek45925ab2007-08-17 16:46:58 +00002567 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
2568 SourceLocation ReturnLoc);
Ted Kremenek30c66752007-11-25 00:58:00 +00002569 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner4b009652007-07-25 00:24:17 +00002570};
2571
Mike Stumpae93d652009-02-19 22:01:56 +00002572
Ted Kremenek0c97e042009-02-07 01:47:29 +00002573//===--------------------------------------------------------------------===//
2574// Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
2575template <typename T>
2576class ExprOwningPtr : public Action::ExprArg {
2577public:
Douglas Gregorbd300312009-03-12 16:53:44 +00002578 ExprOwningPtr(Sema *S, T *expr) : Action::ExprArg(*S, expr) {}
Ted Kremenek0c97e042009-02-07 01:47:29 +00002579
2580 void reset(T* p) { Action::ExprArg::operator=(p); }
2581 T* get() const { return static_cast<T*>(Action::ExprArg::get()); }
2582 T* take() { return static_cast<T*>(Action::ExprArg::take()); }
2583 T* release() { return take(); }
2584
2585 T& operator*() const { return *get(); }
2586 T* operator->() const { return get(); }
2587};
2588
Chris Lattner4b009652007-07-25 00:24:17 +00002589} // end namespace clang
2590
2591#endif