blob: 6ad65e5ba3ab1ba6850abfa4eecf6d7aebc8506d [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +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 Lattner7f925cc2008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "clang/Parse/Action.h"
Anders Carlssonc1fcb772007-07-22 07:07:56 +000021#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian85ff2642007-10-05 18:00:57 +000022#include "llvm/ADT/DenseSet.h"
Chris Lattnerf3876682007-10-07 01:13:46 +000023#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +000024#include "llvm/ADT/OwningPtr.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000025#include <vector>
26#include <string>
27
Chris Lattnerf4021e72007-08-23 05:46:52 +000028namespace llvm {
29 class APSInt;
30}
31
Reid Spencer5f016e22007-07-11 17:01:13 +000032namespace clang {
33 class ASTContext;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000034 class ASTConsumer;
Reid Spencer5f016e22007-07-11 17:01:13 +000035 class Preprocessor;
36 class Decl;
Chris Lattnerb048c982008-04-06 04:47:34 +000037 class DeclContext;
Daniel Dunbar12bc6922008-08-11 03:27:53 +000038 class DeclSpec;
Steve Naroffe8043c32008-04-01 23:04:06 +000039 class NamedDecl;
Steve Naroffc752d042007-09-13 18:10:37 +000040 class ScopedDecl;
Reid Spencer5f016e22007-07-11 17:01:13 +000041 class Expr;
Steve Naroff6f9f3072007-09-02 15:34:30 +000042 class InitListExpr;
Chris Lattner925e60d2007-12-28 05:29:59 +000043 class CallExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000044 class VarDecl;
45 class ParmVarDecl;
46 class TypedefDecl;
47 class FunctionDecl;
48 class QualType;
Chris Lattner701e5eb2007-09-04 02:45:27 +000049 struct LangOptions;
Chris Lattnerd2177732007-07-20 16:59:19 +000050 class Token;
Reid Spencer5f016e22007-07-11 17:01:13 +000051 class IntegerLiteral;
Steve Naroffa49e1fa2008-01-22 00:55:40 +000052 class StringLiteral;
Reid Spencer5f016e22007-07-11 17:01:13 +000053 class ArrayType;
54 class LabelStmt;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000055 class SwitchStmt;
Nate Begeman213541a2008-04-18 23:10:10 +000056 class ExtVectorType;
Steve Naroffbea0b342007-07-29 16:33:31 +000057 class TypedefDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000058 class ObjCInterfaceDecl;
Steve Naroffe8043c32008-04-01 23:04:06 +000059 class ObjCCompatibleAliasDecl;
Ted Kremeneka526c5c2008-01-07 19:49:32 +000060 class ObjCProtocolDecl;
61 class ObjCImplementationDecl;
62 class ObjCCategoryImplDecl;
63 class ObjCCategoryDecl;
64 class ObjCIvarDecl;
65 class ObjCMethodDecl;
Fariborz Jahanian02edb982008-05-01 00:03:38 +000066 class ObjCPropertyDecl;
Steve Naroff4eb206b2008-09-03 18:15:37 +000067 struct BlockSemaInfo;
Steve Naroffbea0b342007-07-29 16:33:31 +000068
Reid Spencer5f016e22007-07-11 17:01:13 +000069/// Sema - This implements semantic analysis and AST building for C.
70class Sema : public Action {
Chris Lattner0b2f4da2008-06-29 00:28:59 +000071public:
Reid Spencer5f016e22007-07-11 17:01:13 +000072 Preprocessor &PP;
Reid Spencer5f016e22007-07-11 17:01:13 +000073 ASTContext &Context;
Chris Lattner2ae34ed2008-02-06 00:46:58 +000074 ASTConsumer &Consumer;
Steve Naroff03300712007-11-12 13:56:41 +000075
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +000076 /// CurContext - This is the current declaration context of parsing.
Chris Lattnerb048c982008-04-06 04:47:34 +000077 DeclContext *CurContext;
Chris Lattner0ed844b2008-04-04 06:12:32 +000078
Steve Naroff4eb206b2008-09-03 18:15:37 +000079 /// CurBlock - If inside of a block definition, this contains a pointer to
80 /// the active block object that represents it.
81 BlockSemaInfo *CurBlock;
82
Reid Spencer5f016e22007-07-11 17:01:13 +000083 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
84 /// it (which acts like the label decl in some ways). Forward referenced
85 /// labels have a LabelStmt created for them with a null location & SubStmt.
86 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000087
88 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffbea0b342007-07-29 16:33:31 +000089
Nate Begeman213541a2008-04-18 23:10:10 +000090 /// ExtVectorDecls - This is a list all the extended vector types. This allows
91 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffbea0b342007-07-29 16:33:31 +000092 /// This is only necessary for issuing pretty diagnostics.
Nate Begeman213541a2008-04-18 23:10:10 +000093 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattner59907c42007-08-10 20:18:51 +000094
Steve Naroffe84a8642008-09-28 14:55:53 +000095 /// ObjCImplementations - Keep track of all class @implementations
96 /// so we can emit errors on duplicates.
Ted Kremeneka526c5c2008-01-07 19:49:32 +000097 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattnerf3876682007-10-07 01:13:46 +000098
Steve Naroffe84a8642008-09-28 14:55:53 +000099 /// ObjCCategoryImpls - Maintain a list of category implementations so
100 /// we can check for duplicates and find local method declarations.
101 llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
102
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000103 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian05672a02007-10-09 18:03:53 +0000104 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner4de884d2007-10-09 18:18:24 +0000105 /// find the declarations when needed.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000106 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff31102512008-04-02 18:30:49 +0000107
108 /// ObjCInterfaceDecls - Keep track of all class declarations declared
109 /// with @interface, so that we can emit errors on duplicates and
110 /// find the declarations when needed.
111 typedef llvm::DenseMap<const IdentifierInfo*,
112 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
113 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
114
Steve Naroffe8043c32008-04-01 23:04:06 +0000115 /// ObjCAliasDecls - Keep track of all class declarations declared
116 /// with @compatibility_alias, so that we can emit errors on duplicates and
117 /// find the declarations when needed. This construct is ancient and will
118 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroffc822ff42008-04-02 00:39:51 +0000119 typedef llvm::DenseMap<const IdentifierInfo*,
120 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroffe8043c32008-04-01 23:04:06 +0000121 ObjCAliasTy ObjCAliasDecls;
Steve Naroff31102512008-04-02 18:30:49 +0000122
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000123 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
124 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
125
Chris Lattner7f925cc2008-04-11 07:00:53 +0000126 IdentifierResolver IdResolver;
127
Chris Lattner59907c42007-08-10 20:18:51 +0000128 // Enum values used by KnownFunctionIDs (see below).
129 enum {
Ted Kremenek7ff22b22008-06-16 18:00:42 +0000130 id_NSLog,
Daniel Dunbarde454282008-10-02 18:44:07 +0000131 id_asprintf,
132 id_fprintf,
133 id_printf,
134 id_snprintf,
135 id_snprintf_chk,
136 id_sprintf,
137 id_sprintf_chk,
Chris Lattner59907c42007-08-10 20:18:51 +0000138 id_vasprintf,
Daniel Dunbarde454282008-10-02 18:44:07 +0000139 id_vfprintf,
140 id_vsnprintf,
141 id_vsnprintf_chk,
Chris Lattner59907c42007-08-10 20:18:51 +0000142 id_vsprintf,
Daniel Dunbarde454282008-10-02 18:44:07 +0000143 id_vsprintf_chk,
Chris Lattner59907c42007-08-10 20:18:51 +0000144 id_vprintf,
145 id_num_known_functions
146 };
147
148 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
149 /// of known functions used by the semantic analysis to do various
150 /// kinds of checking (e.g. checking format string errors in printf calls).
151 /// This list is populated upon the creation of a Sema object.
Chris Lattner06f54852008-08-23 02:00:52 +0000152 IdentifierInfo* KnownFunctionIDs[id_num_known_functions];
Daniel Dunbar662e8b52008-08-14 22:04:54 +0000153
154 /// SuperID - Identifier for "super" used for Objective-C checking.
155 IdentifierInfo* SuperID;
156
Steve Naroff2b255c42008-09-09 14:32:20 +0000157 /// Identifiers for builtin ObjC typedef names.
158 IdentifierInfo *Ident_id, *Ident_Class; // "id", "Class"
159 IdentifierInfo *Ident_SEL, *Ident_Protocol; // "SEL", "Protocol"
160
Steve Naroffe440eb82007-10-10 17:32:04 +0000161 /// Translation Unit Scope - useful to Objective-C actions that need
162 /// to lookup file scope declarations in the "ordinary" C decl namespace.
163 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffb216c882007-10-09 22:01:59 +0000164 Scope *TUScope;
Steve Naroff3b950172007-10-10 21:53:07 +0000165
Steve Naroff58ff9e82007-10-14 00:58:41 +0000166 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000167 struct ObjCMethodList {
168 ObjCMethodDecl *Method;
169 ObjCMethodList *Next;
Steve Naroff58ff9e82007-10-14 00:58:41 +0000170
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000171 ObjCMethodList() {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000172 Method = 0;
173 Next = 0;
174 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000175 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff58ff9e82007-10-14 00:58:41 +0000176 Method = M;
177 Next = C;
178 }
179 };
180 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
181 /// messages to "id". We need to maintain a list, since selectors can have
182 /// differing signatures across classes. In Cocoa, this happens to be
183 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000184 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
185 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Reid Spencer5f016e22007-07-11 17:01:13 +0000186public:
Chris Lattner2ae34ed2008-02-06 00:46:58 +0000187 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Reid Spencer5f016e22007-07-11 17:01:13 +0000188
189 const LangOptions &getLangOptions() const;
190
191 /// The primitive diagnostic helpers - always returns true, which simplifies
192 /// error handling (i.e. less code).
193 bool Diag(SourceLocation Loc, unsigned DiagID);
194 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
195 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
196 const std::string &Msg2);
197
198 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000199 bool Diag(SourceLocation Loc, unsigned DiagID, const SourceRange& R1);
Reid Spencer5f016e22007-07-11 17:01:13 +0000200 bool Diag(SourceLocation Loc, unsigned DiagID,
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000201 const SourceRange& R1, const SourceRange& R2);
Reid Spencer5f016e22007-07-11 17:01:13 +0000202 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000203 const SourceRange& R1);
Reid Spencer5f016e22007-07-11 17:01:13 +0000204 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000205 const SourceRange& R1, const SourceRange& R2);
Reid Spencer5f016e22007-07-11 17:01:13 +0000206 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000207 const std::string &Msg2, const SourceRange& R1);
Chris Lattner4667ac32008-01-03 23:38:43 +0000208 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000209 const std::string &Msg2, const std::string &Msg3,
210 const SourceRange& R1);
Reid Spencer5f016e22007-07-11 17:01:13 +0000211 bool Diag(SourceLocation Loc, unsigned DiagID,
212 const std::string &Msg1, const std::string &Msg2,
Argyrios Kyrtzidisa88b5092008-08-24 13:14:02 +0000213 const SourceRange& R1, const SourceRange& R2);
Fariborz Jahanian9d048ff2007-09-29 00:54:24 +0000214
Chris Lattner394a3fd2007-08-31 04:53:24 +0000215 virtual void DeleteExpr(ExprTy *E);
216 virtual void DeleteStmt(StmtTy *S);
217
Chris Lattner9299f3f2008-08-23 03:19:52 +0000218 virtual void ActOnEndOfTranslationUnit();
219
Reid Spencer5f016e22007-07-11 17:01:13 +0000220 //===--------------------------------------------------------------------===//
221 // Type Analysis / Processing: SemaType.cpp.
222 //
Chris Lattnerfca0ddd2008-06-26 06:27:57 +0000223 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnerc9b346d2008-06-29 00:50:08 +0000224 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Reid Spencer5f016e22007-07-11 17:01:13 +0000225 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
Chris Lattnerf1d705c2008-02-21 01:07:18 +0000226
Reid Spencer5f016e22007-07-11 17:01:13 +0000227
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000228 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian306d68f2007-11-08 23:49:49 +0000229
230
Steve Naroff08d92e42007-09-15 18:49:24 +0000231 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000232private:
233 //===--------------------------------------------------------------------===//
234 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
235 //
Argyrios Kyrtzidis39caa082008-08-01 10:35:27 +0000236 virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S);
Daniel Dunbar914701e2008-08-05 16:28:08 +0000237 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
Chris Lattner04421082008-04-08 04:40:51 +0000238 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
239 virtual void ActOnParamDefaultArgument(DeclTy *param,
240 SourceLocation EqualLoc,
241 ExprTy *defarg);
Steve Naroffbb204692007-09-12 14:07:44 +0000242 void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
Reid Spencer5f016e22007-07-11 17:01:13 +0000243 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
244
Chris Lattnerb652cea2007-10-09 17:14:05 +0000245 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000246 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000247 virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D);
Steve Naroffd6d054d2007-11-11 23:20:51 +0000248
249 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body);
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000250 virtual DeclTy *ActOnLinkageSpec(SourceLocation Loc, SourceLocation LBrace,
Nate Begeman1abc7f62008-02-20 22:57:40 +0000251 SourceLocation RBrace, const char *Lang,
252 unsigned StrSize, DeclTy *D);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000253 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *expr);
254
Steve Naroffb216c882007-10-09 22:01:59 +0000255 /// Scope actions.
256 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
257 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Reid Spencer5f016e22007-07-11 17:01:13 +0000258
259 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
260 /// no declarator (e.g. "struct foo;") is parsed.
261 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
262
Steve Naroff08d92e42007-09-15 18:49:24 +0000263 virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
Reid Spencer5f016e22007-07-11 17:01:13 +0000264 SourceLocation KWLoc, IdentifierInfo *Name,
265 SourceLocation NameLoc, AttributeList *Attr);
Ted Kremenek4b7c9832008-09-05 17:16:31 +0000266
267 DeclTy* ActOnTagStruct(Scope *S, TagDecl::TagKind Kind, TagKind TK,
268 SourceLocation KWLoc, IdentifierInfo *Name,
269 SourceLocation NameLoc, AttributeList *Attr);
270
Chris Lattner06f54852008-08-23 02:00:52 +0000271 virtual void ActOnDefs(Scope *S, SourceLocation DeclStart,
272 IdentifierInfo *ClassName,
273 llvm::SmallVectorImpl<DeclTy*> &Decls);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000274 virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart,
Reid Spencer5f016e22007-07-11 17:01:13 +0000275 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000276
277 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
278 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian45bc03f2008-04-11 16:55:42 +0000279 tok::ObjCKeywordKind visibility);
Fariborz Jahanian1d78cc42008-04-10 23:32:45 +0000280
Steve Narofff13271f2007-09-14 23:09:53 +0000281 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian9d048ff2007-09-29 00:54:24 +0000282 virtual void ActOnFields(Scope* S,
Steve Naroff60fccee2007-10-29 21:38:07 +0000283 SourceLocation RecLoc, DeclTy *TagDecl,
284 DeclTy **Fields, unsigned NumFields,
Daniel Dunbar1bfe1c22008-10-03 02:03:53 +0000285 SourceLocation LBrac, SourceLocation RBrac,
286 AttributeList *AttrList);
Steve Naroff08d92e42007-09-15 18:49:24 +0000287 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000288 DeclTy *LastEnumConstant,
289 SourceLocation IdLoc, IdentifierInfo *Id,
290 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff08d92e42007-09-15 18:49:24 +0000291 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Reid Spencer5f016e22007-07-11 17:01:13 +0000292 DeclTy **Elements, unsigned NumElements);
293private:
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000294 DeclContext *getDCParent(DeclContext *DC);
295
Chris Lattner0ed844b2008-04-04 06:12:32 +0000296 /// Set the current declaration context until it gets popped.
Chris Lattner9fdf9c62008-04-22 18:39:57 +0000297 void PushDeclContext(DeclContext *DC);
Chris Lattnerb048c982008-04-06 04:47:34 +0000298 void PopDeclContext();
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +0000299
300 /// CurFunctionDecl - If inside of a function body, this returns a pointer to
301 /// the function decl for the function being parsed.
302 FunctionDecl *getCurFunctionDecl() {
303 return dyn_cast<FunctionDecl>(CurContext);
304 }
305
306 /// CurMethodDecl - If inside of a method body, this returns a pointer to
307 /// the method decl for the method being parsed.
Daniel Dunbarc4a1dea2008-08-11 05:35:13 +0000308 ObjCMethodDecl *getCurMethodDecl();
Chris Lattner0ed844b2008-04-04 06:12:32 +0000309
Argyrios Kyrtzidis87f3ff02008-04-12 00:47:19 +0000310 /// Add this decl to the scope shadowed decl chains.
311 void PushOnScopeChains(NamedDecl *D, Scope *S);
312
Argyrios Kyrtzidis15a12d02008-09-09 21:18:04 +0000313 /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
314 /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
315 /// true if 'D' belongs to the given declaration context.
316 bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
317 return IdResolver.isDeclInScope(D, Ctx, S);
318 }
319
Chris Lattnerf1d705c2008-02-21 01:07:18 +0000320 /// Subroutines of ActOnDeclarator().
Chris Lattner41af0932007-11-14 06:34:38 +0000321 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
322 ScopedDecl *LastDecl);
Steve Naroffe8043c32008-04-01 23:04:06 +0000323 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
Douglas Gregorf0097952008-04-21 02:02:58 +0000324 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old,
325 bool &Redeclaration);
Steve Naroffe8043c32008-04-01 23:04:06 +0000326 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
Chris Lattner04421082008-04-08 04:40:51 +0000327 FunctionDecl *MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroffff9eb1f2008-08-08 17:50:35 +0000328 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
329
Chris Lattner04421082008-04-08 04:40:51 +0000330 /// Helpers for dealing with function parameters
331 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner04421082008-04-08 04:40:51 +0000332 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregor6d6eb572008-05-07 04:49:29 +0000333 void CheckExtraCXXDefaultArguments(Declarator &D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000334
335 /// More parsing and symbol table subroutines...
Steve Naroffb327ce02008-04-02 14:35:35 +0000336 Decl *LookupDecl(const IdentifierInfo *II, unsigned NSI, Scope *S,
337 bool enableLazyBuiltinCreation = true);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000338 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Steve Naroffb327ce02008-04-02 14:35:35 +0000339 ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
340 Scope *S);
Steve Naroff8c9f13e2007-09-16 16:16:00 +0000341 ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Reid Spencer5f016e22007-07-11 17:01:13 +0000342 Scope *S);
343 // Decl attributes - this routine is the top level dispatcher.
Chris Lattnere5c5ee12008-06-29 00:16:31 +0000344 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnerf2e4bd52008-06-28 23:58:55 +0000345 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lambebb97e92008-02-04 02:31:56 +0000346
Steve Naroff3c2eb662008-02-10 21:38:56 +0000347 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
348 bool &IncompleteImpl);
349
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000350 /// CheckProtocolMethodDefs - This routine checks unimpletented
351 /// methods declared in protocol, and those referenced by it.
352 /// \param IDecl - Used for checking for methods which may have been
353 /// inherited.
Steve Naroffefe7f362008-02-08 22:06:17 +0000354 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
355 ObjCProtocolDecl *PDecl,
Fariborz Jahanianca3adf72007-10-02 20:06:01 +0000356 bool& IncompleteImpl,
Steve Naroffeefc4182007-10-08 21:05:34 +0000357 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000358 const llvm::DenseSet<Selector> &ClsMap,
359 ObjCInterfaceDecl *IDecl);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000360
Steve Naroffa5997c42007-10-02 21:43:37 +0000361 /// CheckImplementationIvars - This routine checks if the instance variables
362 /// listed in the implelementation match those listed in the interface.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000363 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
364 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff3c2eb662008-02-10 21:38:56 +0000365 SourceLocation Loc);
Steve Naroffa5997c42007-10-02 21:43:37 +0000366
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000367 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
368 /// remains unimplemented in the @implementation class.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000369 void ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
370 ObjCInterfaceDecl* IDecl);
Fariborz Jahanian8c74fa42007-09-29 17:14:55 +0000371
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000372 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
373 /// category interface is implemented in the category @implementation.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000374 void ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
375 ObjCCategoryDecl *CatClassDecl);
Fariborz Jahanian85ff2642007-10-05 18:00:57 +0000376 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
377 /// true, or false, accordingly.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000378 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
379 const ObjCMethodDecl *PrevMethod);
Steve Naroff3b950172007-10-10 21:53:07 +0000380
Steve Naroff58ff9e82007-10-14 00:58:41 +0000381 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
382 /// unit are added to a global pool. This allows us to efficiently associate
383 /// a selector with a method declaraation for purposes of typechecking
384 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000385 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff58ff9e82007-10-14 00:58:41 +0000386
Steve Naroff037cda52008-09-30 14:38:43 +0000387 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if
388 /// there are multiple signatures.
389 ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R);
390
Steve Naroff58ff9e82007-10-14 00:58:41 +0000391 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000392 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Reid Spencer5f016e22007-07-11 17:01:13 +0000393 //===--------------------------------------------------------------------===//
394 // Statement Parsing Callbacks: SemaStmt.cpp.
395public:
Steve Naroff1b273c42007-09-16 14:56:35 +0000396 virtual StmtResult ActOnExprStmt(ExprTy *Expr);
Reid Spencer5f016e22007-07-11 17:01:13 +0000397
Steve Naroff1b273c42007-09-16 14:56:35 +0000398 virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
399 virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattner98414c12007-08-31 21:49:55 +0000400 StmtTy **Elts, unsigned NumElts,
401 bool isStmtExpr);
Chris Lattner81c018d2008-03-13 06:29:04 +0000402 virtual StmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
403 SourceLocation EndLoc);
Steve Naroff1b273c42007-09-16 14:56:35 +0000404 virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
Reid Spencer5f016e22007-07-11 17:01:13 +0000405 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
406 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff1b273c42007-09-16 14:56:35 +0000407 virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
Chris Lattner6c36be52007-07-18 02:28:47 +0000408 SourceLocation ColonLoc, StmtTy *SubStmt,
409 Scope *CurScope);
Steve Naroff1b273c42007-09-16 14:56:35 +0000410 virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Reid Spencer5f016e22007-07-11 17:01:13 +0000411 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff1b273c42007-09-16 14:56:35 +0000412 virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Reid Spencer5f016e22007-07-11 17:01:13 +0000413 StmtTy *ThenVal, SourceLocation ElseLoc,
414 StmtTy *ElseVal);
Steve Naroff1b273c42007-09-16 14:56:35 +0000415 virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
Chris Lattner85994262007-10-05 20:15:24 +0000416 virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
417 StmtTy *Switch, ExprTy *Body);
Steve Naroff1b273c42007-09-16 14:56:35 +0000418 virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
Reid Spencer5f016e22007-07-11 17:01:13 +0000419 StmtTy *Body);
Steve Naroff1b273c42007-09-16 14:56:35 +0000420 virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Reid Spencer5f016e22007-07-11 17:01:13 +0000421 SourceLocation WhileLoc, ExprTy *Cond);
422
Steve Naroff1b273c42007-09-16 14:56:35 +0000423 virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000424 SourceLocation LParenLoc,
425 StmtTy *First, ExprTy *Second, ExprTy *Third,
426 SourceLocation RParenLoc, StmtTy *Body);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000427 virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
Fariborz Jahanian3ba5a0f2008-01-03 17:55:25 +0000428 SourceLocation LParenLoc,
429 StmtTy *First, ExprTy *Second,
430 SourceLocation RParenLoc, StmtTy *Body);
431
Steve Naroff1b273c42007-09-16 14:56:35 +0000432 virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000433 SourceLocation LabelLoc,
434 IdentifierInfo *LabelII);
Steve Naroff1b273c42007-09-16 14:56:35 +0000435 virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000436 SourceLocation StarLoc,
437 ExprTy *DestExp);
Steve Naroff1b273c42007-09-16 14:56:35 +0000438 virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000439 Scope *CurScope);
Steve Naroff1b273c42007-09-16 14:56:35 +0000440 virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000441
Steve Naroff1b273c42007-09-16 14:56:35 +0000442 virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000443 ExprTy *RetValExp);
Steve Naroff4eb206b2008-09-03 18:15:37 +0000444 StmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
Reid Spencer5f016e22007-07-11 17:01:13 +0000445
Anders Carlsson6a0ef4b2007-11-20 19:21:03 +0000446 virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
Anders Carlssondfab34a2008-02-05 23:03:50 +0000447 bool IsSimple,
Anders Carlsson39c47b52007-11-23 23:12:25 +0000448 bool IsVolatile,
Anders Carlssonb235fc22007-11-22 01:36:19 +0000449 unsigned NumOutputs,
450 unsigned NumInputs,
451 std::string *Names,
452 ExprTy **Constraints,
453 ExprTy **Exprs,
Anders Carlsson6a0ef4b2007-11-20 19:21:03 +0000454 ExprTy *AsmString,
Anders Carlssonb235fc22007-11-22 01:36:19 +0000455 unsigned NumClobbers,
456 ExprTy **Clobbers,
Chris Lattnerfe795952007-10-29 04:04:16 +0000457 SourceLocation RParenLoc);
458
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000459 virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
Fariborz Jahanian3b1191d2007-11-01 23:59:59 +0000460 SourceLocation RParen, StmtTy *Parm,
461 StmtTy *Body, StmtTy *CatchList);
462
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000463 virtual StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
Fariborz Jahanian161a9c52007-11-02 00:18:53 +0000464 StmtTy *Body);
465
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000466 virtual StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
Fariborz Jahanianbd49a642007-11-02 15:39:31 +0000467 StmtTy *Try,
468 StmtTy *Catch, StmtTy *Finally);
469
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000470 virtual StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Fariborz Jahanian39f8f152007-11-07 02:00:49 +0000471 StmtTy *Throw);
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +0000472 virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
473 ExprTy *SynchExpr,
474 StmtTy *SynchBody);
Fariborz Jahanian39f8f152007-11-07 02:00:49 +0000475
Reid Spencer5f016e22007-07-11 17:01:13 +0000476 //===--------------------------------------------------------------------===//
477 // Expression Parsing Callbacks: SemaExpr.cpp.
478
479 // Primary Expressions.
Steve Naroff08d92e42007-09-15 18:49:24 +0000480 virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000481 IdentifierInfo &II,
482 bool HasTrailingLParen);
Chris Lattnerd9f69102008-08-10 01:53:14 +0000483 virtual ExprResult ActOnPredefinedExpr(SourceLocation Loc,
484 tok::TokenKind Kind);
Steve Narofff69936d2007-09-16 03:34:24 +0000485 virtual ExprResult ActOnNumericConstant(const Token &);
486 virtual ExprResult ActOnCharacterConstant(const Token &);
487 virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
Reid Spencer5f016e22007-07-11 17:01:13 +0000488 ExprTy *Val);
489
Steve Narofff69936d2007-09-16 03:34:24 +0000490 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Reid Spencer5f016e22007-07-11 17:01:13 +0000491 /// fragments (e.g. "foo" "bar" L"baz").
Steve Narofff69936d2007-09-16 03:34:24 +0000492 virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
Reid Spencer5f016e22007-07-11 17:01:13 +0000493
494 // Binary/Unary Operators. 'Tok' is the token for the operator.
Steve Narofff69936d2007-09-16 03:34:24 +0000495 virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
Reid Spencer5f016e22007-07-11 17:01:13 +0000496 ExprTy *Input);
497 virtual ExprResult
Steve Narofff69936d2007-09-16 03:34:24 +0000498 ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
Reid Spencer5f016e22007-07-11 17:01:13 +0000499 SourceLocation LParenLoc, TypeTy *Ty,
500 SourceLocation RParenLoc);
501
Steve Narofff69936d2007-09-16 03:34:24 +0000502 virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000503 tok::TokenKind Kind, ExprTy *Input);
504
Steve Narofff69936d2007-09-16 03:34:24 +0000505 virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000506 ExprTy *Idx, SourceLocation RLoc);
Steve Narofff69936d2007-09-16 03:34:24 +0000507 virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000508 tok::TokenKind OpKind,
509 SourceLocation MemberLoc,
510 IdentifierInfo &Member);
511
Steve Narofff69936d2007-09-16 03:34:24 +0000512 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Reid Spencer5f016e22007-07-11 17:01:13 +0000513 /// This provides the location of the left/right parens and a list of comma
514 /// locations.
Steve Narofff69936d2007-09-16 03:34:24 +0000515 virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000516 ExprTy **Args, unsigned NumArgs,
517 SourceLocation *CommaLocs,
518 SourceLocation RParenLoc);
519
Steve Narofff69936d2007-09-16 03:34:24 +0000520 virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
Reid Spencer5f016e22007-07-11 17:01:13 +0000521 SourceLocation RParenLoc, ExprTy *Op);
Steve Naroff4aa88f82007-07-19 01:06:55 +0000522
Steve Narofff69936d2007-09-16 03:34:24 +0000523 virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
Steve Naroff4aa88f82007-07-19 01:06:55 +0000524 SourceLocation RParenLoc, ExprTy *Op);
Reid Spencer5f016e22007-07-11 17:01:13 +0000525
Steve Narofff69936d2007-09-16 03:34:24 +0000526 virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
Steve Naroff4aa88f82007-07-19 01:06:55 +0000527 ExprTy **InitList, unsigned NumInit,
528 SourceLocation RParenLoc);
529
Steve Narofff69936d2007-09-16 03:34:24 +0000530 virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
Reid Spencer5f016e22007-07-11 17:01:13 +0000531 ExprTy *LHS,ExprTy *RHS);
532
Steve Narofff69936d2007-09-16 03:34:24 +0000533 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Reid Spencer5f016e22007-07-11 17:01:13 +0000534 /// in the case of a the GNU conditional expr extension.
Steve Narofff69936d2007-09-16 03:34:24 +0000535 virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000536 SourceLocation ColonLoc,
537 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
538
Steve Naroff1b273c42007-09-16 14:56:35 +0000539 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
540 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000541 IdentifierInfo *LabelII);
542
Steve Naroff1b273c42007-09-16 14:56:35 +0000543 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattnerab18c4c2007-07-24 16:58:17 +0000544 SourceLocation RPLoc); // "({..})"
Chris Lattner73d0d4f2007-08-30 17:45:32 +0000545
546 /// __builtin_offsetof(type, a.b[123][456].c)
Steve Naroff1b273c42007-09-16 14:56:35 +0000547 virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
Chris Lattner73d0d4f2007-08-30 17:45:32 +0000548 SourceLocation TypeLoc, TypeTy *Arg1,
549 OffsetOfComponent *CompPtr,
550 unsigned NumComponents,
551 SourceLocation RParenLoc);
552
Steve Naroffd34e9152007-08-01 22:05:33 +0000553 // __builtin_types_compatible_p(type1, type2)
Steve Naroff1b273c42007-09-16 14:56:35 +0000554 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroffd34e9152007-08-01 22:05:33 +0000555 TypeTy *arg1, TypeTy *arg2,
556 SourceLocation RPLoc);
Steve Naroffd04fdd52007-08-03 21:21:27 +0000557
558 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff1b273c42007-09-16 14:56:35 +0000559 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroffd04fdd52007-08-03 21:21:27 +0000560 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
561 SourceLocation RPLoc);
Chris Lattnerab18c4c2007-07-24 16:58:17 +0000562
Nate Begemane2ce1d92008-01-17 17:46:27 +0000563 // __builtin_overload(...)
564 virtual ExprResult ActOnOverloadExpr(ExprTy **Args, unsigned NumArgs,
565 SourceLocation *CommaLocs,
566 SourceLocation BuiltinLoc,
567 SourceLocation RParenLoc);
Nate Begeman440b4562008-03-07 20:04:22 +0000568
Anders Carlsson7c50aca2007-10-15 20:28:48 +0000569 // __builtin_va_arg(expr, type)
570 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
571 ExprTy *expr, TypeTy *type,
572 SourceLocation RPLoc);
Steve Naroff4eb206b2008-09-03 18:15:37 +0000573
574 //===------------------------- "Block" Extension ------------------------===//
575
576 /// ActOnBlockStart - This callback is invoked when a block literal is
577 /// started.
Steve Naroff090276f2008-10-10 01:28:17 +0000578 virtual void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope);
579
580 /// ActOnBlockArguments - This callback allows processing of block arguments.
581 /// If there are no arguments, this is still invoked.
582 virtual void ActOnBlockArguments(Declarator &ParamInfo);
Steve Naroff4eb206b2008-09-03 18:15:37 +0000583
584 /// ActOnBlockError - If there is an error parsing a block, this callback
585 /// is invoked to pop the information about the block from the action impl.
586 virtual void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope);
587
588 /// ActOnBlockStmtExpr - This is called when the body of a block statement
589 /// literal was successfully completed. ^(int x){...}
590 virtual ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *Body,
591 Scope *CurScope);
592
Argyrios Kyrtzidis2d1c5d32008-04-27 13:50:30 +0000593 // Act on C++ namespaces
594 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
595 IdentifierInfo *Ident,
596 SourceLocation LBrace);
597 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
598
Argyrios Kyrtzidis73a0d882008-10-06 17:10:33 +0000599 /// AddCXXDirectInitializerToDecl - This action is called immediately after
600 /// ActOnDeclarator, when a C++ direct initializer is present.
601 /// e.g: "int x(1);"
602 virtual void AddCXXDirectInitializerToDecl(DeclTy *Dcl,
603 SourceLocation LParenLoc,
604 ExprTy **Exprs, unsigned NumExprs,
605 SourceLocation *CommaLocs,
606 SourceLocation RParenLoc);
607
Steve Naroff1b273c42007-09-16 14:56:35 +0000608 /// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
609 virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
Reid Spencer5f016e22007-07-11 17:01:13 +0000610 SourceLocation LAngleBracketLoc, TypeTy *Ty,
611 SourceLocation RAngleBracketLoc,
612 SourceLocation LParenLoc, ExprTy *E,
613 SourceLocation RParenLoc);
614
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000615 //// ActOnCXXThis - Parse 'this' pointer.
616 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
617
Steve Naroff1b273c42007-09-16 14:56:35 +0000618 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
619 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000620 tok::TokenKind Kind);
Anders Carlsson55085182007-08-21 17:43:55 +0000621
Chris Lattner50dd2892008-02-26 00:51:44 +0000622 //// ActOnCXXThrow - Parse throw expressions.
623 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
624 ExprTy *expr);
625
Argyrios Kyrtzidis987a14b2008-08-22 15:38:55 +0000626 /// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
627 /// Can be interpreted either as function-style casting ("int(x)")
628 /// or class type construction ("ClassType(x,y,z)")
629 /// or creation of a value-initialized type ("int()").
630 virtual ExprResult ActOnCXXTypeConstructExpr(SourceRange TypeRange,
631 TypeTy *TypeRep,
632 SourceLocation LParenLoc,
633 ExprTy **Exprs,
634 unsigned NumExprs,
635 SourceLocation *CommaLocs,
636 SourceLocation RParenLoc);
637
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +0000638 /// ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a
639 /// C++ if/switch/while/for statement.
640 /// e.g: "if (int x = f()) {...}"
641 virtual ExprResult ActOnCXXConditionDeclarationExpr(Scope *S,
642 SourceLocation StartLoc,
643 Declarator &D,
644 SourceLocation EqualLoc,
645 ExprTy *AssignExprVal);
646
Anders Carlsson55085182007-08-21 17:43:55 +0000647 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnerb3a99cd2007-12-12 01:04:12 +0000648 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
649 ExprTy **Strings,
650 unsigned NumStrings);
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000651 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner674af952007-10-16 22:51:17 +0000652 SourceLocation EncodeLoc,
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000653 SourceLocation LParenLoc,
654 TypeTy *Ty,
655 SourceLocation RParenLoc);
656
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000657 // ParseObjCSelectorExpression - Build selector expression for @selector
658 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
659 SourceLocation AtLoc,
Fariborz Jahanian2a35fa92007-10-16 23:21:02 +0000660 SourceLocation SelLoc,
Fariborz Jahanianb62f6812007-10-16 20:40:23 +0000661 SourceLocation LParenLoc,
662 SourceLocation RParenLoc);
663
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000664 // ParseObjCProtocolExpression - Build protocol expression for @protocol
665 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
666 SourceLocation AtLoc,
667 SourceLocation ProtoLoc,
668 SourceLocation LParenLoc,
669 SourceLocation RParenLoc);
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000670
671 //===--------------------------------------------------------------------===//
672 // C++ Classes
673 //
674 /// ActOnBaseSpecifier - Parsed a base specifier
675 virtual void ActOnBaseSpecifier(DeclTy *classdecl, SourceRange SpecifierRange,
676 bool Virtual, AccessSpecifier Access,
Argyrios Kyrtzidis39caa082008-08-01 10:35:27 +0000677 TypeTy *basetype, SourceLocation BaseLoc);
Fariborz Jahanian390d50a2007-10-17 16:58:11 +0000678
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000679 virtual void ActOnStartCXXClassDef(Scope *S, DeclTy *TagDecl,
680 SourceLocation LBrace);
681
682 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
683 Declarator &D, ExprTy *BitfieldWidth,
684 ExprTy *Init, DeclTy *LastInGroup);
685
686 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
687 DeclTy *TagDecl,
688 SourceLocation LBrac,
689 SourceLocation RBrac);
690
Argyrios Kyrtzidis5b7f0c82008-08-09 00:39:29 +0000691 virtual void ActOnFinishCXXClassDef(DeclTy *TagDecl);
Argyrios Kyrtzidis07952322008-07-01 10:37:29 +0000692
Douglas Gregore37ac4f2008-04-13 21:30:24 +0000693
Steve Naroff3536b442007-09-06 21:24:23 +0000694 // Objective-C declarations.
Chris Lattner06036d32008-07-26 04:13:19 +0000695 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
696 IdentifierInfo *ClassName,
697 SourceLocation ClassLoc,
698 IdentifierInfo *SuperName,
699 SourceLocation SuperLoc,
700 DeclTy * const *ProtoRefs,
701 unsigned NumProtoRefs,
702 SourceLocation EndProtoLoc,
703 AttributeList *AttrList);
Fariborz Jahanian243b64b2007-10-11 23:42:27 +0000704
705 virtual DeclTy *ActOnCompatiblityAlias(
706 SourceLocation AtCompatibilityAliasLoc,
707 IdentifierInfo *AliasName, SourceLocation AliasLocation,
708 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff3536b442007-09-06 21:24:23 +0000709
Steve Naroffe440eb82007-10-10 17:32:04 +0000710 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman1abc7f62008-02-20 22:57:40 +0000711 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000712 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattnere13b9592008-07-26 04:03:38 +0000713 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Daniel Dunbar246e70f2008-09-26 04:48:09 +0000714 SourceLocation EndProtoLoc,
715 AttributeList *AttrList);
Fariborz Jahanian25e077d2007-09-17 21:07:36 +0000716
Chris Lattner6bd6d0b2008-07-26 04:07:02 +0000717 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
718 IdentifierInfo *ClassName,
719 SourceLocation ClassLoc,
720 IdentifierInfo *CategoryName,
721 SourceLocation CategoryLoc,
722 DeclTy * const *ProtoRefs,
723 unsigned NumProtoRefs,
724 SourceLocation EndProtoLoc);
Fariborz Jahanianfd225cc2007-09-18 20:26:58 +0000725
Steve Naroffe440eb82007-10-10 17:32:04 +0000726 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman1abc7f62008-02-20 22:57:40 +0000727 SourceLocation AtClassImplLoc,
Fariborz Jahanianccb4f312007-09-25 18:38:09 +0000728 IdentifierInfo *ClassName, SourceLocation ClassLoc,
729 IdentifierInfo *SuperClassname,
730 SourceLocation SuperClassLoc);
731
Steve Naroffe440eb82007-10-10 17:32:04 +0000732 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian8f3fde02007-10-02 16:38:50 +0000733 SourceLocation AtCatImplLoc,
734 IdentifierInfo *ClassName,
735 SourceLocation ClassLoc,
736 IdentifierInfo *CatName,
737 SourceLocation CatLoc);
738
Steve Naroffe440eb82007-10-10 17:32:04 +0000739 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff37e58d12007-10-02 22:39:18 +0000740 IdentifierInfo **IdentList,
741 unsigned NumElts);
Fariborz Jahanian894c57f2007-09-21 15:40:54 +0000742
Steve Naroffe440eb82007-10-10 17:32:04 +0000743 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000744 const IdentifierLocPair *IdentList,
Steve Naroff37e58d12007-10-02 22:39:18 +0000745 unsigned NumElts);
Fariborz Jahanian245f92a2007-10-05 21:01:53 +0000746
Chris Lattnere13b9592008-07-26 04:03:38 +0000747 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000748 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian4b6c9052007-10-11 00:55:41 +0000749 unsigned NumProtocols,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000750 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian02edb982008-05-01 00:03:38 +0000751
Daniel Dunbar95e61fb2008-09-23 21:53:23 +0000752 /// Ensure attributes are consistent with type.
753 /// \param [in, out] Attributes The attributes to check; they will
754 /// be modified to be consistent with \arg PropertyTy.
755 void CheckObjCPropertyAttributes(QualType PropertyTy,
756 SourceLocation Loc,
757 unsigned &Attributes);
Fariborz Jahanian02edb982008-05-01 00:03:38 +0000758 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
759 ObjCPropertyDecl *SuperProperty,
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +0000760 const char *Name);
Fariborz Jahanian02edb982008-05-01 00:03:38 +0000761 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanianb5e02242008-04-24 19:58:34 +0000762
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +0000763 void MergeProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
764 DeclTy *MergeProtocols);
765
766 void MergeOneProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
767 ObjCProtocolDecl *PDecl);
768
Steve Naroff0416fb92007-11-11 17:19:15 +0000769 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
770 DeclTy **allMethods = 0, unsigned allNum = 0,
771 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahaniand0b90bf2007-09-26 18:27:25 +0000772
Fariborz Jahanian1de1e742008-04-14 23:36:35 +0000773 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +0000774 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian5251e132008-05-06 18:09:04 +0000775 Selector GetterSel, Selector SetterSel,
Fariborz Jahanian46b55e52008-05-05 18:51:55 +0000776 tok::ObjCKeywordKind MethodImplKind);
777
Fariborz Jahanianf624f812008-04-18 00:19:30 +0000778 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
779 SourceLocation PropertyLoc,
780 bool ImplKind, DeclTy *ClassImplDecl,
781 IdentifierInfo *PropertyId,
782 IdentifierInfo *PropertyIvar);
783
Steve Naroffbef11852007-10-26 20:53:56 +0000784 virtual DeclTy *ActOnMethodDeclaration(
785 SourceLocation BeginLoc, // location of the + or -.
786 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanian1f7b6f82007-11-09 19:52:12 +0000787 tok::TokenKind MethodType,
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000788 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanianf1de0ca2007-10-31 23:53:01 +0000789 Selector Sel,
Steve Naroff68d331a2007-09-27 14:38:14 +0000790 // optional arguments. The number of types/arguments is obtained
791 // from the Sel.getNumArgs().
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000792 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Steve Naroff335eafa2007-11-15 12:35:21 +0000793 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
794 bool isVariadic = false);
Steve Naroff81bfde92007-10-16 23:12:48 +0000795
Steve Naroff68d331a2007-09-27 14:38:14 +0000796 // ActOnClassMessage - used for both unary and keyword messages.
797 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +0000798 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +0000799 virtual ExprResult ActOnClassMessage(
Fariborz Jahanian0523aaf2007-11-12 20:13:27 +0000800 Scope *S,
Steve Naroffbcfb06a2007-09-28 22:22:11 +0000801 IdentifierInfo *receivingClassName, Selector Sel,
Steve Naroff49f109c2007-11-15 13:05:42 +0000802 SourceLocation lbrac, SourceLocation rbrac,
803 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff68d331a2007-09-27 14:38:14 +0000804
805 // ActOnInstanceMessage - used for both unary and keyword messages.
806 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroff49f109c2007-11-15 13:05:42 +0000807 // is obtained from NumArgs.
Steve Naroff68d331a2007-09-27 14:38:14 +0000808 virtual ExprResult ActOnInstanceMessage(
Steve Naroffbcfb06a2007-09-28 22:22:11 +0000809 ExprTy *receiver, Selector Sel,
Steve Naroff49f109c2007-11-15 13:05:42 +0000810 SourceLocation lbrac, SourceLocation rbrac,
811 ExprTy **ArgExprs, unsigned NumArgs);
Reid Spencer5f016e22007-07-11 17:01:13 +0000812private:
Chris Lattner1e0a3902008-01-16 19:17:22 +0000813 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
814 /// cast. If there is already an implicit cast, merge into the existing one.
815 void ImpCastExprToType(Expr *&Expr, QualType Type);
816
Reid Spencer5f016e22007-07-11 17:01:13 +0000817 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner925e60d2007-12-28 05:29:59 +0000818 // functions and arrays to their respective pointers (C99 6.3.2.1).
819 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3c0eb162008-05-27 03:33:27 +0000820
821 // UsualUnaryConversionType - Same as UsualUnaryConversions, but works
822 // on types instead of expressions
823 QualType UsualUnaryConversionType(QualType Ty);
Steve Naroffc80b4ee2007-07-16 21:54:35 +0000824
825 // DefaultFunctionArrayConversion - converts functions and arrays
826 // to their respective pointers (C99 6.3.2.1).
827 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroff90045e82007-07-13 23:32:42 +0000828
Steve Naroffb291ab62007-08-28 23:30:39 +0000829 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
830 // do not have a prototype. Integer promotions are performed on each
831 // argument, and arguments that have type float are promoted to double.
Chris Lattner925e60d2007-12-28 05:29:59 +0000832 void DefaultArgumentPromotion(Expr *&Expr);
Steve Naroffb291ab62007-08-28 23:30:39 +0000833
Reid Spencer5f016e22007-07-11 17:01:13 +0000834 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
835 // operands and then handles various conversions that are common to binary
836 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
837 // routine returns the first non-arithmetic type found. The client is
838 // responsible for emitting appropriate error diagnostics.
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000839 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
840 bool isCompAssign = false);
Chris Lattnerb7b61152008-01-04 18:22:42 +0000841
842 /// AssignConvertType - All of the 'assignment' semantic checks return this
843 /// enum to indicate whether the assignment was allowed. These checks are
844 /// done for simple assignments, as well as initialization, return from
845 /// function, argument passing, etc. The query is phrased in terms of a
846 /// source and destination type.
Chris Lattner5cf216b2008-01-04 18:04:52 +0000847 enum AssignConvertType {
Chris Lattnerb7b61152008-01-04 18:22:42 +0000848 /// Compatible - the types are compatible according to the standard.
Reid Spencer5f016e22007-07-11 17:01:13 +0000849 Compatible,
Chris Lattnerb7b61152008-01-04 18:22:42 +0000850
851 /// PointerToInt - The assignment converts a pointer to an int, which we
852 /// accept as an extension.
853 PointerToInt,
854
855 /// IntToPointer - The assignment converts an int to a pointer, which we
856 /// accept as an extension.
857 IntToPointer,
858
859 /// FunctionVoidPointer - The assignment is between a function pointer and
860 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattnerbfe639e2008-01-03 22:56:36 +0000861 FunctionVoidPointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +0000862
863 /// IncompatiblePointer - The assignment is between two pointers types that
864 /// are not compatible, but we accept them as an extension.
Reid Spencer5f016e22007-07-11 17:01:13 +0000865 IncompatiblePointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +0000866
867 /// CompatiblePointerDiscardsQualifiers - The assignment discards
868 /// c/v/r qualifiers, which we accept as an extension.
869 CompatiblePointerDiscardsQualifiers,
Steve Naroff1c7d0672008-09-04 15:10:53 +0000870
Steve Naroffbfdcae62008-09-04 15:31:07 +0000871 /// IntToBlockPointer - The assignment converts an int to a block
Steve Naroff1c7d0672008-09-04 15:10:53 +0000872 /// pointer. We disallow this.
873 IntToBlockPointer,
874
Steve Naroffbfdcae62008-09-04 15:31:07 +0000875 /// IncompatibleBlockPointer - The assignment is between two block
Steve Naroff1c7d0672008-09-04 15:10:53 +0000876 /// pointers types that are not compatible.
877 IncompatibleBlockPointer,
878
Steve Naroffbfdcae62008-09-04 15:31:07 +0000879 /// BlockVoidPointer - The assignment is between a block pointer and
Steve Naroff1c7d0672008-09-04 15:10:53 +0000880 /// void*, we accept for now.
881 BlockVoidPointer,
Chris Lattnerb7b61152008-01-04 18:22:42 +0000882
883 /// Incompatible - We reject this conversion outright, it is invalid to
884 /// represent it in the AST.
885 Incompatible
Reid Spencer5f016e22007-07-11 17:01:13 +0000886 };
Chris Lattner5cf216b2008-01-04 18:04:52 +0000887
888 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
889 /// assignment conversion type specified by ConvTy. This returns true if the
890 /// conversion was invalid or false if the conversion was accepted.
891 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
892 SourceLocation Loc,
893 QualType DstType, QualType SrcType,
894 Expr *SrcExpr, const char *Flavor);
895
896 /// CheckAssignmentConstraints - Perform type checking for assignment,
897 /// argument passing, variable initialization, and function return values.
898 /// This routine is only used by the following two methods. C99 6.5.16.
899 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +0000900
Steve Narofff69936d2007-09-16 03:34:24 +0000901 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff1b273c42007-09-16 14:56:35 +0000902 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroff90045e82007-07-13 23:32:42 +0000903 // this routine performs the default function/array converions.
Chris Lattner5cf216b2008-01-04 18:04:52 +0000904 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
905 Expr *&rExpr);
Steve Naroff90045e82007-07-13 23:32:42 +0000906 // CheckCompoundAssignmentConstraints - Type check without performing any
907 // conversions. For compound assignments, the "Check...Operands" methods
908 // perform the necessary conversions.
Chris Lattner5cf216b2008-01-04 18:04:52 +0000909 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
910 QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +0000911
Reid Spencer5f016e22007-07-11 17:01:13 +0000912 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner5cf216b2008-01-04 18:04:52 +0000913 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
914 QualType rhsType);
Steve Naroff1c7d0672008-09-04 15:10:53 +0000915
916 // Helper function for CheckAssignmentConstraints involving two
917 // blcok pointer types.
918 AssignConvertType CheckBlockPointerTypesForAssignment(QualType lhsType,
919 QualType rhsType);
Douglas Gregor77a52232008-09-12 00:47:35 +0000920
921 bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000922
923 /// the following "Check" methods will return a valid/converted QualType
924 /// or a null QualType (indicating an error diagnostic was issued).
925
Steve Narofff69936d2007-09-16 03:34:24 +0000926 /// type checking binary operators (subroutines of ActOnBinOp).
Chris Lattnerca5eede2007-12-12 05:47:28 +0000927 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Reid Spencer5f016e22007-07-11 17:01:13 +0000928 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000929 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000930 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000931 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000932 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000933 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000934 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000935 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000936 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000937 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnera5937dd2007-08-26 01:18:55 +0000938 inline QualType CheckCompareOperands( // C99 6.5.8/9
939 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Reid Spencer5f016e22007-07-11 17:01:13 +0000940 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000941 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000942 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff49b45262007-07-13 16:58:59 +0000943 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000944 // CheckAssignmentOperands is used for both simple and compound assignment.
945 // For simple assignment, pass both expressions and a null converted type.
946 // For compound assignment, pass both expressions and the converted type.
947 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Narofff1120de2007-08-24 22:33:52 +0000948 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000949 inline QualType CheckCommaOperands( // C99 6.5.17
Steve Naroff49b45262007-07-13 16:58:59 +0000950 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000951 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff49b45262007-07-13 16:58:59 +0000952 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begemanbe2341d2008-07-14 18:02:46 +0000953
954 /// type checking for vector binary operators.
955 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
956 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
957 SourceLocation l, bool isRel);
Reid Spencer5f016e22007-07-11 17:01:13 +0000958
Steve Narofff69936d2007-09-16 03:34:24 +0000959 /// type checking unary operators (subroutines of ActOnUnaryOp).
Reid Spencer5f016e22007-07-11 17:01:13 +0000960 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
961 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
962 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
963 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattnerbb280a42008-07-25 21:45:37 +0000964 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
965 const SourceRange &R, bool isSizeof);
Chris Lattner5d794252007-08-24 21:41:10 +0000966 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroffe1b31fe2007-07-27 22:15:19 +0000967
968 /// type checking primary expressions.
Nate Begeman213541a2008-04-18 23:10:10 +0000969 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Naroffe1b31fe2007-07-27 22:15:19 +0000970 IdentifierInfo &Comp, SourceLocation CmpLoc);
971
Steve Narofff0090632007-09-02 02:04:30 +0000972 /// type checking declaration initializers (C99 6.7.8)
Steve Naroff0cca7492008-05-01 22:18:59 +0000973 friend class InitListChecker;
Steve Naroffd0091aa2008-01-10 22:15:12 +0000974 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType);
975 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
Steve Naroffd0091aa2008-01-10 22:15:12 +0000976 bool CheckForConstantInitializer(Expr *e, QualType t);
Eli Friedmanc594b322008-05-20 13:48:25 +0000977 bool CheckArithmeticConstantExpression(const Expr* e);
978 bool CheckAddressConstantExpression(const Expr* e);
979 bool CheckAddressConstantExpressionLValue(const Expr* e);
Steve Naroff2fdc3742007-12-10 22:44:33 +0000980
Steve Naroffa49e1fa2008-01-22 00:55:40 +0000981 StringLiteral *IsStringLiteralInit(Expr *Init, QualType DeclType);
982 bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT);
Argyrios Kyrtzidis6c2dc4d2008-08-16 20:27:34 +0000983
984 /// CheckCastTypes - Check type constraints for casting between types.
Daniel Dunbar58d5ebb2008-08-20 03:55:42 +0000985 bool CheckCastTypes(SourceRange TyRange, QualType CastTy, Expr *&CastExpr);
Steve Naroffa49e1fa2008-01-22 00:55:40 +0000986
Anders Carlsson584b2472007-11-27 07:16:40 +0000987 // CheckVectorCast - check type constraints for vectors.
988 // Since vectors are an extension, there are no C standard reference for this.
989 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssona64db8f2007-11-27 05:51:55 +0000990 // returns true if the cast is invalid
991 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
992
Daniel Dunbar637cebb2008-09-11 00:01:56 +0000993 /// CheckMessageArgumentTypes - Check types in an Obj-C message send.
994 /// \param Method - May be null.
995 /// \param [out] ReturnType - The return type of the send.
996 /// \return true iff there were any incompatible types.
Daniel Dunbar91e19b22008-09-11 00:50:25 +0000997 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs, Selector Sel,
Daniel Dunbar637cebb2008-09-11 00:01:56 +0000998 ObjCMethodDecl *Method, const char *PrefixStr,
999 SourceLocation lbrac, SourceLocation rbrac,
1000 QualType &ReturnType);
Argyrios Kyrtzidis59210932008-09-10 02:17:11 +00001001
1002 /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid.
1003 bool CheckCXXBooleanCondition(Expr *&CondExpr);
Steve Naroff81bfde92007-10-16 23:12:48 +00001004
Chris Lattnerf4021e72007-08-23 05:46:52 +00001005 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
1006 /// the specified width and sign. If an overflow occurs, detect it and emit
1007 /// the specified diagnostic.
1008 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
1009 unsigned NewWidth, bool NewSign,
1010 SourceLocation Loc, unsigned DiagID);
1011
Chris Lattnereca7be62008-04-07 05:30:13 +00001012 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
1013 bool ForCompare);
1014
1015
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001016 void InitBuiltinVaListType();
Eli Friedman1b76ada2008-06-03 21:01:11 +00001017
1018 // Helper method to turn variable array types into
1019 // constant array types in certain situations which would otherwise
1020 // be errors
1021 QualType TryFixInvalidVariablyModifiedType(QualType T);
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001022
Chris Lattner59907c42007-08-10 20:18:51 +00001023 //===--------------------------------------------------------------------===//
1024 // Extra semantic analysis beyond the C type system
Chris Lattner925e60d2007-12-28 05:29:59 +00001025private:
Eli Friedmand38617c2008-05-14 19:38:39 +00001026 Action::ExprResult CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
Chris Lattner925e60d2007-12-28 05:29:59 +00001027 bool CheckBuiltinCFStringArgument(Expr* Arg);
1028 bool SemaBuiltinVAStart(CallExpr *TheCall);
1029 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedman6cfda232008-05-20 08:23:37 +00001030 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Eli Friedmand38617c2008-05-14 19:38:39 +00001031 Action::ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbar4493f792008-07-21 22:59:13 +00001032 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Daniel Dunbard5f8a4f2008-09-03 21:13:56 +00001033 bool SemaBuiltinObjectSize(CallExpr *TheCall);
Chris Lattner925e60d2007-12-28 05:29:59 +00001034 void CheckPrintfArguments(CallExpr *TheCall,
1035 bool HasVAListArg, unsigned format_idx);
Ted Kremenek06de2762007-08-17 16:46:58 +00001036 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
1037 SourceLocation ReturnLoc);
Ted Kremenek588e5eb2007-11-25 00:58:00 +00001038 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Reid Spencer5f016e22007-07-11 17:01:13 +00001039};
1040
Steve Naroff0cca7492008-05-01 22:18:59 +00001041class InitListChecker {
1042 Sema *SemaRef;
1043 bool hadError;
1044
1045 void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
1046 unsigned &Index);
Steve Naroffa647caa2008-05-06 00:23:44 +00001047 void CheckExplicitInitList(InitListExpr *IList, QualType &T,
Steve Naroff0cca7492008-05-01 22:18:59 +00001048 unsigned &Index);
1049
Eli Friedmanb85f7072008-05-19 19:16:24 +00001050 void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
1051 unsigned &Index);
1052 void CheckSubElementType(InitListExpr *IList, QualType ElemType,
1053 unsigned &Index);
Steve Naroff0cca7492008-05-01 22:18:59 +00001054 // FIXME: Does DeclType need to be a reference type?
1055 void CheckScalarType(InitListExpr *IList, QualType &DeclType,
1056 unsigned &Index);
1057 void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index);
1058 void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
Eli Friedmanb85f7072008-05-19 19:16:24 +00001059 unsigned &Index);
Steve Naroff0cca7492008-05-01 22:18:59 +00001060 void CheckArrayType(InitListExpr *IList, QualType &DeclType, unsigned &Index);
1061
1062 int numArrayElements(QualType DeclType);
1063 int numStructUnionElements(QualType DeclType);
1064public:
1065 InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
1066 bool HadError() { return hadError; }
1067};
1068
Steve Naroff4eb206b2008-09-03 18:15:37 +00001069/// BlockSemaInfo - When a block is being parsed, this contains information
1070/// about the block. It is pointed to from Sema::CurBlock.
1071struct BlockSemaInfo {
1072 llvm::SmallVector<ParmVarDecl*, 8> Params;
Steve Naroff4eb206b2008-09-03 18:15:37 +00001073 bool hasPrototype;
1074 bool isVariadic;
1075
Steve Naroff1c90bfc2008-10-08 18:44:00 +00001076 BlockDecl *TheDecl;
1077
Steve Naroff4eb206b2008-09-03 18:15:37 +00001078 /// TheScope - This is the scope for the block itself, which contains
1079 /// arguments etc.
1080 Scope *TheScope;
1081
1082 /// ReturnType - This will get set to block result type, by looking at
1083 /// return types, if any, in the block body.
1084 Type *ReturnType;
1085
1086 /// PrevBlockInfo - If this is nested inside another block, this points
1087 /// to the outer block.
1088 BlockSemaInfo *PrevBlockInfo;
1089};
1090
Reid Spencer5f016e22007-07-11 17:01:13 +00001091
1092} // end namespace clang
1093
1094#endif