blob: d6dcaf2b9ae6cbf1ee4caeb20be28b4d6daf7657 [file] [log] [blame]
Chris Lattnercc67ec12006-11-09 06:54:47 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
Chris Lattner7cee11f2006-11-03 06:42:29 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner7cee11f2006-11-03 06:42:29 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattnercc67ec12006-11-09 06:54:47 +000010// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
Chris Lattner7cee11f2006-11-03 06:42:29 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattnercc67ec12006-11-09 06:54:47 +000015#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
Chris Lattner7cee11f2006-11-03 06:42:29 +000017
Chris Lattnerc5c95b52008-04-11 07:00:53 +000018#include "IdentifierResolver.h"
Argyrios Kyrtzidised983422008-07-01 10:37:29 +000019#include "CXXFieldCollector.h"
Chris Lattner7cee11f2006-11-03 06:42:29 +000020#include "clang/Parse/Action.h"
Anders Carlsson51873c22007-07-22 07:07:56 +000021#include "llvm/ADT/SmallVector.h"
Fariborz Jahanian458f7112007-10-05 18:00:57 +000022#include "llvm/ADT/DenseSet.h"
Chris Lattneree2d8412007-10-07 01:13:46 +000023#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidised983422008-07-01 10:37:29 +000024#include "llvm/ADT/OwningPtr.h"
Chris Lattner7cee11f2006-11-03 06:42:29 +000025#include <vector>
Chris Lattnereaafe1222006-11-10 05:17:58 +000026#include <string>
Chris Lattner7cee11f2006-11-03 06:42:29 +000027
Chris Lattnerfc1c44a2007-08-23 05:46:52 +000028namespace llvm {
29 class APSInt;
30}
31
Chris Lattner7cee11f2006-11-03 06:42:29 +000032namespace clang {
Chris Lattnercb6a3822006-11-10 06:20:45 +000033 class ASTContext;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000034 class ASTConsumer;
Chris Lattner7cee11f2006-11-03 06:42:29 +000035 class Preprocessor;
36 class Decl;
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000037 class DeclContext;
Daniel Dunbar34fb6722008-08-11 03:27:53 +000038 class DeclSpec;
Steve Naroff257520b2008-04-01 23:04:06 +000039 class NamedDecl;
Steve Naroff9324db12007-09-13 18:10:37 +000040 class ScopedDecl;
Steve Naroff78403362007-04-02 22:55:05 +000041 class Expr;
Steve Narofff33527a2007-09-02 15:34:30 +000042 class InitListExpr;
Chris Lattner08464942007-12-28 05:29:59 +000043 class CallExpr;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000044 class VarDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000045 class ParmVarDecl;
Chris Lattner01564d92007-01-27 19:27:06 +000046 class TypedefDecl;
47 class FunctionDecl;
Steve Naroffe5aa9be2007-04-05 22:36:20 +000048 class QualType;
Chris Lattner9cf21c52007-09-04 02:45:27 +000049 struct LangOptions;
Chris Lattner146762e2007-07-20 16:59:19 +000050 class Token;
Steve Naroff35d85152007-05-07 00:24:15 +000051 class IntegerLiteral;
Steve Naroffaf2a0222008-01-22 00:55:40 +000052 class StringLiteral;
Steve Naroff8eeeb132007-05-08 21:09:37 +000053 class ArrayType;
Chris Lattnere2473062007-05-28 06:28:18 +000054 class LabelStmt;
Anders Carlsson51873c22007-07-22 07:07:56 +000055 class SwitchStmt;
Nate Begemance4d7fc2008-04-18 23:10:10 +000056 class ExtVectorType;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000057 class TypedefDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000058 class ObjCInterfaceDecl;
Steve Naroff257520b2008-04-01 23:04:06 +000059 class ObjCCompatibleAliasDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000060 class ObjCProtocolDecl;
61 class ObjCImplementationDecl;
62 class ObjCCategoryImplDecl;
63 class ObjCCategoryDecl;
64 class ObjCIvarDecl;
65 class ObjCMethodDecl;
Fariborz Jahanian7cf18862008-05-01 00:03:38 +000066 class ObjCPropertyDecl;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000067
Chris Lattnercc67ec12006-11-09 06:54:47 +000068/// Sema - This implements semantic analysis and AST building for C.
69class Sema : public Action {
Chris Lattnera663a0a2008-06-29 00:28:59 +000070public:
Steve Naroff38d31b42007-02-28 01:22:02 +000071 Preprocessor &PP;
Chris Lattnercb6a3822006-11-10 06:20:45 +000072 ASTContext &Context;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000073 ASTConsumer &Consumer;
Steve Naroffe3d1ab22007-11-12 13:56:41 +000074
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +000075 /// CurContext - This is the current declaration context of parsing.
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000076 DeclContext *CurContext;
Chris Lattnerc5ffed42008-04-04 06:12:32 +000077
Chris Lattnere2473062007-05-28 06:28:18 +000078 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
79 /// it (which acts like the label decl in some ways). Forward referenced
80 /// labels have a LabelStmt created for them with a null location & SubStmt.
Chris Lattner23b7eb62007-06-15 23:05:46 +000081 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
Anders Carlsson51873c22007-07-22 07:07:56 +000082
83 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000084
Nate Begemance4d7fc2008-04-18 23:10:10 +000085 /// ExtVectorDecls - This is a list all the extended vector types. This allows
86 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffddf5a1d2007-07-29 16:33:31 +000087 /// This is only necessary for issuing pretty diagnostics.
Nate Begemance4d7fc2008-04-18 23:10:10 +000088 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattnerb87b1b32007-08-10 20:18:51 +000089
Ted Kremenek1b0ea822008-01-07 19:49:32 +000090 /// ObjCImplementations - Keep track of all of the classes with
Chris Lattneree2d8412007-10-07 01:13:46 +000091 /// @implementation's, so that we can emit errors on duplicates.
Ted Kremenek1b0ea822008-01-07 19:49:32 +000092 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattneree2d8412007-10-07 01:13:46 +000093
Ted Kremenek1b0ea822008-01-07 19:49:32 +000094 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian06f84f52007-10-09 18:03:53 +000095 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner516ca702007-10-09 18:18:24 +000096 /// find the declarations when needed.
Ted Kremenek1b0ea822008-01-07 19:49:32 +000097 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff77892752008-04-02 18:30:49 +000098
99 /// ObjCInterfaceDecls - Keep track of all class declarations declared
100 /// with @interface, so that we can emit errors on duplicates and
101 /// find the declarations when needed.
102 typedef llvm::DenseMap<const IdentifierInfo*,
103 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
104 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
105
Steve Naroff257520b2008-04-01 23:04:06 +0000106 /// ObjCAliasDecls - Keep track of all class declarations declared
107 /// with @compatibility_alias, so that we can emit errors on duplicates and
108 /// find the declarations when needed. This construct is ancient and will
109 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroff9b94b172008-04-02 00:39:51 +0000110 typedef llvm::DenseMap<const IdentifierInfo*,
111 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroff257520b2008-04-01 23:04:06 +0000112 ObjCAliasTy ObjCAliasDecls;
Steve Naroff77892752008-04-02 18:30:49 +0000113
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000114 /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
115 llvm::OwningPtr<CXXFieldCollector> FieldCollector;
116
Chris Lattnerc5c95b52008-04-11 07:00:53 +0000117 IdentifierResolver IdResolver;
118
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000119 // Enum values used by KnownFunctionIDs (see below).
120 enum {
121 id_printf,
122 id_fprintf,
123 id_sprintf,
124 id_snprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000125 id_asprintf,
Ted Kremenek34f664d2008-06-16 18:00:42 +0000126 id_NSLog,
Ted Kremenekcfc94192007-08-10 21:13:51 +0000127 id_vsnprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000128 id_vasprintf,
129 id_vfprintf,
130 id_vsprintf,
131 id_vprintf,
132 id_num_known_functions
133 };
134
135 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
136 /// of known functions used by the semantic analysis to do various
137 /// kinds of checking (e.g. checking format string errors in printf calls).
138 /// This list is populated upon the creation of a Sema object.
139 IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
140
Steve Naroff93eb5f12007-10-10 17:32:04 +0000141 /// Translation Unit Scope - useful to Objective-C actions that need
142 /// to lookup file scope declarations in the "ordinary" C decl namespace.
143 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffc62adb62007-10-09 22:01:59 +0000144 Scope *TUScope;
Steve Naroff7f549f12007-10-10 21:53:07 +0000145
Steve Naroff5811baf2007-10-14 00:58:41 +0000146 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000147 struct ObjCMethodList {
148 ObjCMethodDecl *Method;
149 ObjCMethodList *Next;
Steve Naroff5811baf2007-10-14 00:58:41 +0000150
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000151 ObjCMethodList() {
Steve Naroff5811baf2007-10-14 00:58:41 +0000152 Method = 0;
153 Next = 0;
154 }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000155 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff5811baf2007-10-14 00:58:41 +0000156 Method = M;
157 Next = C;
158 }
159 };
160 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
161 /// messages to "id". We need to maintain a list, since selectors can have
162 /// differing signatures across classes. In Cocoa, this happens to be
163 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000164 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
165 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Chris Lattner7cee11f2006-11-03 06:42:29 +0000166public:
Chris Lattnerfe0e0af2008-02-06 00:46:58 +0000167 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000168
Chris Lattnerac18be92006-11-20 06:49:47 +0000169 const LangOptions &getLangOptions() const;
170
Steve Naroff71ce2e02007-05-18 22:53:50 +0000171 /// The primitive diagnostic helpers - always returns true, which simplifies
172 /// error handling (i.e. less code).
Chris Lattnerd6647d32007-05-16 17:56:50 +0000173 bool Diag(SourceLocation Loc, unsigned DiagID);
174 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
175 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
176 const std::string &Msg2);
Steve Naroff71ce2e02007-05-18 22:53:50 +0000177
178 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
179 bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
180 bool Diag(SourceLocation Loc, unsigned DiagID,
181 SourceRange R1, SourceRange R2);
182 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
183 SourceRange R1);
184 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
185 SourceRange R1, SourceRange R2);
186 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
187 const std::string &Msg2, SourceRange R1);
Chris Lattner816dea22008-01-03 23:38:43 +0000188 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
189 const std::string &Msg2, const std::string &Msg3, SourceRange R1);
Steve Naroff71ce2e02007-05-18 22:53:50 +0000190 bool Diag(SourceLocation Loc, unsigned DiagID,
191 const std::string &Msg1, const std::string &Msg2,
192 SourceRange R1, SourceRange R2);
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000193
Chris Lattner57c523f2007-08-31 04:53:24 +0000194 virtual void DeleteExpr(ExprTy *E);
195 virtual void DeleteStmt(StmtTy *S);
196
Chris Lattner7cee11f2006-11-03 06:42:29 +0000197 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000198 // Type Analysis / Processing: SemaType.cpp.
199 //
Chris Lattner4b413ea2008-06-26 06:27:57 +0000200 QualType ConvertDeclSpecToType(const DeclSpec &DS);
Chris Lattnera7e619c2008-06-29 00:50:08 +0000201 void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
Steve Naroffe5aa9be2007-04-05 22:36:20 +0000202 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000203
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000204
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000205 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian56ff1462007-11-08 23:49:49 +0000206
207
Steve Naroff30d242c2007-09-15 18:49:24 +0000208 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Steve Naroff26c8ea52007-03-21 21:08:52 +0000209private:
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000210 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000211 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000212 //
Argyrios Kyrtzidis25d05e82008-08-01 10:35:27 +0000213 virtual TypeTy *isTypeName(const IdentifierInfo &II, Scope *S);
Daniel Dunbar1ff1d1f2008-08-05 16:28:08 +0000214 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000215 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
216 virtual void ActOnParamDefaultArgument(DeclTy *param,
217 SourceLocation EqualLoc,
218 ExprTy *defarg);
Steve Naroff61091402007-09-12 14:07:44 +0000219 void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
Chris Lattner776fac82007-06-09 00:53:06 +0000220 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
221
Chris Lattnera55a2cc2007-10-09 17:14:05 +0000222 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000223 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000224 virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D);
Steve Naroffb313fc32007-11-11 23:20:51 +0000225
226 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body);
Chris Lattner38376f12008-01-12 07:05:38 +0000227 virtual DeclTy *ActOnLinkageSpec(SourceLocation Loc, SourceLocation LBrace,
Nate Begeman7dd8e722008-02-20 22:57:40 +0000228 SourceLocation RBrace, const char *Lang,
229 unsigned StrSize, DeclTy *D);
Anders Carlsson5c6c0592008-02-08 00:33:21 +0000230 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *expr);
231
Steve Naroffc62adb62007-10-09 22:01:59 +0000232 /// Scope actions.
233 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
234 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000235
Chris Lattner200bdc32006-11-19 02:43:37 +0000236 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
237 /// no declarator (e.g. "struct foo;") is parsed.
238 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
239
Steve Naroff30d242c2007-09-15 18:49:24 +0000240 virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
Chris Lattnerf34c4da2007-01-23 04:08:05 +0000241 SourceLocation KWLoc, IdentifierInfo *Name,
Steve Naroffb3096442007-06-09 03:47:53 +0000242 SourceLocation NameLoc, AttributeList *Attr);
Chris Lattner535b8302008-06-21 19:39:06 +0000243 virtual void ActOnDefs(Scope *S, SourceLocation DeclStart, IdentifierInfo
Chris Lattnerd7352d62008-07-21 22:17:28 +0000244 *ClassName, llvm::SmallVectorImpl<DeclTy*> &Decls);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000245 virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart,
Chris Lattner1300fb92007-01-23 23:42:53 +0000246 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000247
248 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
249 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian96376742008-04-11 16:55:42 +0000250 tok::ObjCKeywordKind visibility);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000251
Steve Naroff2e688fd2007-09-14 23:09:53 +0000252 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000253 virtual void ActOnFields(Scope* S,
Steve Naroff33a1e802007-10-29 21:38:07 +0000254 SourceLocation RecLoc, DeclTy *TagDecl,
255 DeclTy **Fields, unsigned NumFields,
Fariborz Jahaniande615832008-04-10 23:32:45 +0000256 SourceLocation LBrac, SourceLocation RBrac);
Steve Naroff30d242c2007-09-15 18:49:24 +0000257 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000258 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000259 SourceLocation IdLoc, IdentifierInfo *Id,
260 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff30d242c2007-09-15 18:49:24 +0000261 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000262 DeclTy **Elements, unsigned NumElements);
Steve Naroff3273c222007-03-14 21:52:03 +0000263private:
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000264 DeclContext *getDCParent(DeclContext *DC);
265
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000266 /// Set the current declaration context until it gets popped.
Chris Lattnerbec41342008-04-22 18:39:57 +0000267 void PushDeclContext(DeclContext *DC);
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000268 void PopDeclContext();
Argyrios Kyrtzidis853fbea2008-06-28 06:07:14 +0000269
270 /// CurFunctionDecl - If inside of a function body, this returns a pointer to
271 /// the function decl for the function being parsed.
272 FunctionDecl *getCurFunctionDecl() {
273 return dyn_cast<FunctionDecl>(CurContext);
274 }
275
276 /// CurMethodDecl - If inside of a method body, this returns a pointer to
277 /// the method decl for the method being parsed.
Daniel Dunbar6e8aa532008-08-11 05:35:13 +0000278 ObjCMethodDecl *getCurMethodDecl();
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000279
Argyrios Kyrtzidisb8a49202008-04-12 00:47:19 +0000280 /// Add this decl to the scope shadowed decl chains.
281 void PushOnScopeChains(NamedDecl *D, Scope *S);
282
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000283 /// Subroutines of ActOnDeclarator().
Chris Lattner07b201d2007-11-14 06:34:38 +0000284 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
285 ScopedDecl *LastDecl);
Steve Naroff257520b2008-04-01 23:04:06 +0000286 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
Douglas Gregor89f238c2008-04-21 02:02:58 +0000287 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old,
288 bool &Redeclaration);
Steve Naroff257520b2008-04-01 23:04:06 +0000289 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000290 FunctionDecl *MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
Steve Naroff5bb8f222008-08-08 17:50:35 +0000291 void CheckForFileScopedRedefinitions(Scope *S, VarDecl *VD);
292
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000293 /// Helpers for dealing with function parameters
294 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner5696e7b2008-06-17 18:05:57 +0000295 ImplicitParamDecl *CreateImplicitParameter(Scope *S, IdentifierInfo *Id,
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000296 SourceLocation IdLoc, QualType Type);
297 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregorcaa8ace2008-05-07 04:49:29 +0000298 void CheckExtraCXXDefaultArguments(Declarator &D);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000299
Steve Naroff3273c222007-03-14 21:52:03 +0000300 /// More parsing and symbol table subroutines...
Steve Naroff2fc93f52008-04-02 14:35:35 +0000301 Decl *LookupDecl(const IdentifierInfo *II, unsigned NSI, Scope *S,
302 bool enableLazyBuiltinCreation = true);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000303 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Steve Naroff2fc93f52008-04-02 14:35:35 +0000304 ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
305 Scope *S);
Steve Naroff2f742082007-09-16 16:16:00 +0000306 ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Steve Naroff3273c222007-03-14 21:52:03 +0000307 Scope *S);
Steve Naroffa8fd9732007-06-11 00:35:03 +0000308 // Decl attributes - this routine is the top level dispatcher.
Chris Lattner58418ff2008-06-29 00:16:31 +0000309 void ProcessDeclAttributes(Decl *D, const Declarator &PD);
Chris Lattnera5741542008-06-28 23:58:55 +0000310 void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000311
Steve Naroff15833ed2008-02-10 21:38:56 +0000312 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
313 bool &IncompleteImpl);
314
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000315 /// CheckProtocolMethodDefs - This routine checks unimpletented methods
316 /// Declared in protocol, and those referenced by it.
Steve Naroffa36992242008-02-08 22:06:17 +0000317 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
318 ObjCProtocolDecl *PDecl,
Fariborz Jahanianadf84f32007-10-02 20:06:01 +0000319 bool& IncompleteImpl,
Steve Naroff71c3c1c2007-10-08 21:05:34 +0000320 const llvm::DenseSet<Selector> &InsMap,
Chris Lattnerdadc7622007-10-05 20:15:24 +0000321 const llvm::DenseSet<Selector> &ClsMap);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000322
Steve Naroffd1741552007-10-02 21:43:37 +0000323 /// CheckImplementationIvars - This routine checks if the instance variables
324 /// listed in the implelementation match those listed in the interface.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000325 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
326 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff15833ed2008-02-10 21:38:56 +0000327 SourceLocation Loc);
Steve Naroffd1741552007-10-02 21:43:37 +0000328
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000329 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
330 /// remains unimplemented in the @implementation class.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000331 void ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
332 ObjCInterfaceDecl* IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000333
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +0000334 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
335 /// category interface is implemented in the category @implementation.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000336 void ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
337 ObjCCategoryDecl *CatClassDecl);
Fariborz Jahanian458f7112007-10-05 18:00:57 +0000338 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
339 /// true, or false, accordingly.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000340 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
341 const ObjCMethodDecl *PrevMethod);
Steve Naroff7f549f12007-10-10 21:53:07 +0000342
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000343 /// isBuiltinObjCType - Returns true of the type is "id", "SEL", "Class"
Fariborz Jahanian2bbd03a2007-12-07 00:18:54 +0000344 /// or "Protocol".
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000345 bool isBuiltinObjCType(TypedefDecl *TD);
Anders Carlssonf56a7ae2007-10-31 02:53:19 +0000346
Steve Naroff5811baf2007-10-14 00:58:41 +0000347 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
348 /// unit are added to a global pool. This allows us to efficiently associate
349 /// a selector with a method declaraation for purposes of typechecking
350 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000351 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff5811baf2007-10-14 00:58:41 +0000352
353 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000354 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000355 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000356 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +0000357public:
Steve Naroff66356bd2007-09-16 14:56:35 +0000358 virtual StmtResult ActOnExprStmt(ExprTy *Expr);
Chris Lattner1ec5f562007-06-27 05:38:08 +0000359
Steve Naroff66356bd2007-09-16 14:56:35 +0000360 virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
361 virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnercac27a52007-08-31 21:49:55 +0000362 StmtTy **Elts, unsigned NumElts,
363 bool isStmtExpr);
Chris Lattner2e232092008-03-13 06:29:04 +0000364 virtual StmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
365 SourceLocation EndLoc);
Steve Naroff66356bd2007-09-16 14:56:35 +0000366 virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
Chris Lattner6c0ff132006-11-05 00:19:50 +0000367 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
368 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff66356bd2007-09-16 14:56:35 +0000369 virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
Chris Lattner46eeb222007-07-18 02:28:47 +0000370 SourceLocation ColonLoc, StmtTy *SubStmt,
371 Scope *CurScope);
Steve Naroff66356bd2007-09-16 14:56:35 +0000372 virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Chris Lattner6c0ff132006-11-05 00:19:50 +0000373 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff66356bd2007-09-16 14:56:35 +0000374 virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000375 StmtTy *ThenVal, SourceLocation ElseLoc,
376 StmtTy *ElseVal);
Steve Naroff66356bd2007-09-16 14:56:35 +0000377 virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
Chris Lattnerdadc7622007-10-05 20:15:24 +0000378 virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
379 StmtTy *Switch, ExprTy *Body);
Steve Naroff66356bd2007-09-16 14:56:35 +0000380 virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
Chris Lattner85ed8732006-11-04 20:40:44 +0000381 StmtTy *Body);
Steve Naroff66356bd2007-09-16 14:56:35 +0000382 virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner85ed8732006-11-04 20:40:44 +0000383 SourceLocation WhileLoc, ExprTy *Cond);
384
Steve Naroff66356bd2007-09-16 14:56:35 +0000385 virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
Chris Lattner71e23ce2006-11-04 20:18:38 +0000386 SourceLocation LParenLoc,
387 StmtTy *First, ExprTy *Second, ExprTy *Third,
388 SourceLocation RParenLoc, StmtTy *Body);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000389 virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
Fariborz Jahanian732b8c22008-01-03 17:55:25 +0000390 SourceLocation LParenLoc,
391 StmtTy *First, ExprTy *Second,
392 SourceLocation RParenLoc, StmtTy *Body);
393
Steve Naroff66356bd2007-09-16 14:56:35 +0000394 virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
Chris Lattner16976d32006-11-05 01:46:01 +0000395 SourceLocation LabelLoc,
396 IdentifierInfo *LabelII);
Steve Naroff66356bd2007-09-16 14:56:35 +0000397 virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattner16976d32006-11-05 01:46:01 +0000398 SourceLocation StarLoc,
399 ExprTy *DestExp);
Steve Naroff66356bd2007-09-16 14:56:35 +0000400 virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Chris Lattnereaafe1222006-11-10 05:17:58 +0000401 Scope *CurScope);
Steve Naroff66356bd2007-09-16 14:56:35 +0000402 virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Chris Lattner71e23ce2006-11-04 20:18:38 +0000403
Steve Naroff66356bd2007-09-16 14:56:35 +0000404 virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000405 ExprTy *RetValExp);
406
Anders Carlsson81a5a692007-11-20 19:21:03 +0000407 virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
Anders Carlsson19fe1162008-02-05 23:03:50 +0000408 bool IsSimple,
Anders Carlsson660bdd12007-11-23 23:12:25 +0000409 bool IsVolatile,
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000410 unsigned NumOutputs,
411 unsigned NumInputs,
412 std::string *Names,
413 ExprTy **Constraints,
414 ExprTy **Exprs,
Anders Carlsson81a5a692007-11-20 19:21:03 +0000415 ExprTy *AsmString,
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000416 unsigned NumClobbers,
417 ExprTy **Clobbers,
Chris Lattner73c56c02007-10-29 04:04:16 +0000418 SourceLocation RParenLoc);
419
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000420 virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
Fariborz Jahanian9e63b982007-11-01 23:59:59 +0000421 SourceLocation RParen, StmtTy *Parm,
422 StmtTy *Body, StmtTy *CatchList);
423
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000424 virtual StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
Fariborz Jahanian71234d82007-11-02 00:18:53 +0000425 StmtTy *Body);
426
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000427 virtual StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
Fariborz Jahanianf859ef22007-11-02 15:39:31 +0000428 StmtTy *Try,
429 StmtTy *Catch, StmtTy *Finally);
430
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000431 virtual StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000432 StmtTy *Throw);
Fariborz Jahanian48085b82008-01-29 19:14:59 +0000433 virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
434 ExprTy *SynchExpr,
435 StmtTy *SynchBody);
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000436
Chris Lattner7cee11f2006-11-03 06:42:29 +0000437 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000438 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000439
440 // Primary Expressions.
Steve Naroff30d242c2007-09-15 18:49:24 +0000441 virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
Chris Lattnerac18be92006-11-20 06:49:47 +0000442 IdentifierInfo &II,
443 bool HasTrailingLParen);
Chris Lattner6307f192008-08-10 01:53:14 +0000444 virtual ExprResult ActOnPredefinedExpr(SourceLocation Loc,
445 tok::TokenKind Kind);
Steve Naroff83895f72007-09-16 03:34:24 +0000446 virtual ExprResult ActOnNumericConstant(const Token &);
447 virtual ExprResult ActOnCharacterConstant(const Token &);
448 virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000449 ExprTy *Val);
Chris Lattner697e5d62006-11-09 06:32:27 +0000450
Steve Naroff83895f72007-09-16 03:34:24 +0000451 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +0000452 /// fragments (e.g. "foo" "bar" L"baz").
Steve Naroff83895f72007-09-16 03:34:24 +0000453 virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
Chris Lattner697e5d62006-11-09 06:32:27 +0000454
Chris Lattner7cee11f2006-11-03 06:42:29 +0000455 // Binary/Unary Operators. 'Tok' is the token for the operator.
Steve Naroff83895f72007-09-16 03:34:24 +0000456 virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000457 ExprTy *Input);
458 virtual ExprResult
Steve Naroff83895f72007-09-16 03:34:24 +0000459 ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000460 SourceLocation LParenLoc, TypeTy *Ty,
461 SourceLocation RParenLoc);
462
Steve Naroff83895f72007-09-16 03:34:24 +0000463 virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000464 tok::TokenKind Kind, ExprTy *Input);
465
Steve Naroff83895f72007-09-16 03:34:24 +0000466 virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000467 ExprTy *Idx, SourceLocation RLoc);
Steve Naroff83895f72007-09-16 03:34:24 +0000468 virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000469 tok::TokenKind OpKind,
470 SourceLocation MemberLoc,
471 IdentifierInfo &Member);
472
Steve Naroff83895f72007-09-16 03:34:24 +0000473 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000474 /// This provides the location of the left/right parens and a list of comma
475 /// locations.
Steve Naroff83895f72007-09-16 03:34:24 +0000476 virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000477 ExprTy **Args, unsigned NumArgs,
478 SourceLocation *CommaLocs,
479 SourceLocation RParenLoc);
480
Steve Naroff83895f72007-09-16 03:34:24 +0000481 virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000482 SourceLocation RParenLoc, ExprTy *Op);
Steve Narofffbd09832007-07-19 01:06:55 +0000483
Steve Naroff83895f72007-09-16 03:34:24 +0000484 virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
Steve Narofffbd09832007-07-19 01:06:55 +0000485 SourceLocation RParenLoc, ExprTy *Op);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000486
Steve Naroff83895f72007-09-16 03:34:24 +0000487 virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
Steve Narofffbd09832007-07-19 01:06:55 +0000488 ExprTy **InitList, unsigned NumInit,
489 SourceLocation RParenLoc);
490
Steve Naroff83895f72007-09-16 03:34:24 +0000491 virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000492 ExprTy *LHS,ExprTy *RHS);
493
Steve Naroff83895f72007-09-16 03:34:24 +0000494 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner7cee11f2006-11-03 06:42:29 +0000495 /// in the case of a the GNU conditional expr extension.
Steve Naroff83895f72007-09-16 03:34:24 +0000496 virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000497 SourceLocation ColonLoc,
498 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
Chris Lattner29375652006-12-04 18:06:35 +0000499
Steve Naroff66356bd2007-09-16 14:56:35 +0000500 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
501 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattnereefa10e2007-05-28 06:56:27 +0000502 IdentifierInfo *LabelII);
503
Steve Naroff66356bd2007-09-16 14:56:35 +0000504 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner366727f2007-07-24 16:58:17 +0000505 SourceLocation RPLoc); // "({..})"
Chris Lattnerf17bd422007-08-30 17:45:32 +0000506
507 /// __builtin_offsetof(type, a.b[123][456].c)
Steve Naroff66356bd2007-09-16 14:56:35 +0000508 virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
Chris Lattnerf17bd422007-08-30 17:45:32 +0000509 SourceLocation TypeLoc, TypeTy *Arg1,
510 OffsetOfComponent *CompPtr,
511 unsigned NumComponents,
512 SourceLocation RParenLoc);
513
Steve Naroff78864672007-08-01 22:05:33 +0000514 // __builtin_types_compatible_p(type1, type2)
Steve Naroff66356bd2007-09-16 14:56:35 +0000515 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +0000516 TypeTy *arg1, TypeTy *arg2,
517 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +0000518
519 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff66356bd2007-09-16 14:56:35 +0000520 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff9efdabc2007-08-03 21:21:27 +0000521 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
522 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +0000523
Nate Begeman1e36a852008-01-17 17:46:27 +0000524 // __builtin_overload(...)
525 virtual ExprResult ActOnOverloadExpr(ExprTy **Args, unsigned NumArgs,
526 SourceLocation *CommaLocs,
527 SourceLocation BuiltinLoc,
528 SourceLocation RParenLoc);
Nate Begeman0a6192c2008-03-07 20:04:22 +0000529
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000530 // __builtin_va_arg(expr, type)
531 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
532 ExprTy *expr, TypeTy *type,
533 SourceLocation RPLoc);
534
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +0000535 // Act on C++ namespaces
536 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
537 IdentifierInfo *Ident,
538 SourceLocation LBrace);
539 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
540
Steve Naroff66356bd2007-09-16 14:56:35 +0000541 /// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
542 virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
Chris Lattner29375652006-12-04 18:06:35 +0000543 SourceLocation LAngleBracketLoc, TypeTy *Ty,
544 SourceLocation RAngleBracketLoc,
545 SourceLocation LParenLoc, ExprTy *E,
546 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +0000547
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000548 //// ActOnCXXThis - Parse 'this' pointer.
549 virtual ExprResult ActOnCXXThis(SourceLocation ThisLoc);
550
Steve Naroff66356bd2007-09-16 14:56:35 +0000551 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
552 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +0000553 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +0000554
Chris Lattnerb7e656b2008-02-26 00:51:44 +0000555 //// ActOnCXXThrow - Parse throw expressions.
556 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
557 ExprTy *expr);
558
Anders Carlsson76f4a902007-08-21 17:43:55 +0000559 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnere002fbe2007-12-12 01:04:12 +0000560 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
561 ExprTy **Strings,
562 unsigned NumStrings);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000563 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner37390be2007-10-16 22:51:17 +0000564 SourceLocation EncodeLoc,
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000565 SourceLocation LParenLoc,
566 TypeTy *Ty,
567 SourceLocation RParenLoc);
568
Fariborz Jahanian4bef4622007-10-16 20:40:23 +0000569 // ParseObjCSelectorExpression - Build selector expression for @selector
570 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
571 SourceLocation AtLoc,
Fariborz Jahanian6bd1d612007-10-16 23:21:02 +0000572 SourceLocation SelLoc,
Fariborz Jahanian4bef4622007-10-16 20:40:23 +0000573 SourceLocation LParenLoc,
574 SourceLocation RParenLoc);
575
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +0000576 // ParseObjCProtocolExpression - Build protocol expression for @protocol
577 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
578 SourceLocation AtLoc,
579 SourceLocation ProtoLoc,
580 SourceLocation LParenLoc,
581 SourceLocation RParenLoc);
Douglas Gregor556877c2008-04-13 21:30:24 +0000582
583 //===--------------------------------------------------------------------===//
584 // C++ Classes
585 //
586 /// ActOnBaseSpecifier - Parsed a base specifier
587 virtual void ActOnBaseSpecifier(DeclTy *classdecl, SourceRange SpecifierRange,
588 bool Virtual, AccessSpecifier Access,
Argyrios Kyrtzidis25d05e82008-08-01 10:35:27 +0000589 TypeTy *basetype, SourceLocation BaseLoc);
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +0000590
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000591 virtual void ActOnStartCXXClassDef(Scope *S, DeclTy *TagDecl,
592 SourceLocation LBrace);
593
594 virtual DeclTy *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS,
595 Declarator &D, ExprTy *BitfieldWidth,
596 ExprTy *Init, DeclTy *LastInGroup);
597
598 virtual void ActOnFinishCXXMemberSpecification(Scope* S, SourceLocation RLoc,
599 DeclTy *TagDecl,
600 SourceLocation LBrac,
601 SourceLocation RBrac);
602
Argyrios Kyrtzidis5c45c9b2008-08-09 00:39:29 +0000603 virtual void ActOnFinishCXXClassDef(DeclTy *TagDecl);
Argyrios Kyrtzidised983422008-07-01 10:37:29 +0000604
Douglas Gregor556877c2008-04-13 21:30:24 +0000605
Steve Naroff09bf8152007-09-06 21:24:23 +0000606 // Objective-C declarations.
Chris Lattnerdf59f5a2008-07-26 04:13:19 +0000607 virtual DeclTy *ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
608 IdentifierInfo *ClassName,
609 SourceLocation ClassLoc,
610 IdentifierInfo *SuperName,
611 SourceLocation SuperLoc,
612 DeclTy * const *ProtoRefs,
613 unsigned NumProtoRefs,
614 SourceLocation EndProtoLoc,
615 AttributeList *AttrList);
Fariborz Jahanian49c64252007-10-11 23:42:27 +0000616
617 virtual DeclTy *ActOnCompatiblityAlias(
618 SourceLocation AtCompatibilityAliasLoc,
619 IdentifierInfo *AliasName, SourceLocation AliasLocation,
620 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff09bf8152007-09-06 21:24:23 +0000621
Steve Naroff93eb5f12007-10-10 17:32:04 +0000622 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +0000623 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian39d641f2007-09-17 21:07:36 +0000624 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Chris Lattner3bbae002008-07-26 04:03:38 +0000625 DeclTy * const *ProtoRefNames, unsigned NumProtoRefs,
Steve Naroffc5484042007-10-30 02:23:23 +0000626 SourceLocation EndProtoLoc);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +0000627
Chris Lattnerb1f3c942008-07-26 04:07:02 +0000628 virtual DeclTy *ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
629 IdentifierInfo *ClassName,
630 SourceLocation ClassLoc,
631 IdentifierInfo *CategoryName,
632 SourceLocation CategoryLoc,
633 DeclTy * const *ProtoRefs,
634 unsigned NumProtoRefs,
635 SourceLocation EndProtoLoc);
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +0000636
Steve Naroff93eb5f12007-10-10 17:32:04 +0000637 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman7dd8e722008-02-20 22:57:40 +0000638 SourceLocation AtClassImplLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +0000639 IdentifierInfo *ClassName, SourceLocation ClassLoc,
640 IdentifierInfo *SuperClassname,
641 SourceLocation SuperClassLoc);
642
Steve Naroff93eb5f12007-10-10 17:32:04 +0000643 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +0000644 SourceLocation AtCatImplLoc,
645 IdentifierInfo *ClassName,
646 SourceLocation ClassLoc,
647 IdentifierInfo *CatName,
648 SourceLocation CatLoc);
649
Steve Naroff93eb5f12007-10-10 17:32:04 +0000650 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +0000651 IdentifierInfo **IdentList,
652 unsigned NumElts);
Fariborz Jahanian876e27d2007-09-21 15:40:54 +0000653
Steve Naroff93eb5f12007-10-10 17:32:04 +0000654 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattnerd7352d62008-07-21 22:17:28 +0000655 const IdentifierLocPair *IdentList,
Steve Naroff0c37b0c2007-10-02 22:39:18 +0000656 unsigned NumElts);
Fariborz Jahanianea7a98d2007-10-05 21:01:53 +0000657
Chris Lattner3bbae002008-07-26 04:03:38 +0000658 virtual void FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattnerd7352d62008-07-21 22:17:28 +0000659 const IdentifierLocPair *ProtocolId,
Fariborz Jahanian70e8f102007-10-11 00:55:41 +0000660 unsigned NumProtocols,
Chris Lattnerd7352d62008-07-21 22:17:28 +0000661 llvm::SmallVectorImpl<DeclTy *> &Protocols);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +0000662
663 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
664 ObjCPropertyDecl *SuperProperty,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +0000665 const char *Name);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +0000666 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian0a070ff2008-04-24 19:58:34 +0000667
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +0000668 void MergeProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
669 DeclTy *MergeProtocols);
670
671 void MergeOneProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
672 ObjCProtocolDecl *PDecl);
673
Steve Naroffcac26f42007-11-11 17:19:15 +0000674 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
675 DeclTy **allMethods = 0, unsigned allNum = 0,
676 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahanian2a4dd312007-09-26 18:27:25 +0000677
Fariborz Jahanian0152a1a2008-04-14 23:36:35 +0000678 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian8d916862008-05-05 18:51:55 +0000679 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian09367d62008-05-06 18:09:04 +0000680 Selector GetterSel, Selector SetterSel,
Fariborz Jahanian8d916862008-05-05 18:51:55 +0000681 tok::ObjCKeywordKind MethodImplKind);
682
Fariborz Jahanianffe97a32008-04-18 00:19:30 +0000683 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
684 SourceLocation PropertyLoc,
685 bool ImplKind, DeclTy *ClassImplDecl,
686 IdentifierInfo *PropertyId,
687 IdentifierInfo *PropertyIvar);
688
Steve Naroff161a92b2007-10-26 20:53:56 +0000689 virtual DeclTy *ActOnMethodDeclaration(
690 SourceLocation BeginLoc, // location of the + or -.
691 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanianb5605172007-11-09 19:52:12 +0000692 tok::TokenKind MethodType,
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000693 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian7a9c4742007-10-31 23:53:01 +0000694 Selector Sel,
Steve Narofff73590d2007-09-27 14:38:14 +0000695 // optional arguments. The number of types/arguments is obtained
696 // from the Sel.getNumArgs().
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000697 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Steve Naroffd8ea1ac2007-11-15 12:35:21 +0000698 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
699 bool isVariadic = false);
Steve Naroff077c83b2007-10-16 23:12:48 +0000700
Steve Narofff73590d2007-09-27 14:38:14 +0000701 // ActOnClassMessage - used for both unary and keyword messages.
702 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000703 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +0000704 virtual ExprResult ActOnClassMessage(
Fariborz Jahaniand98a7342007-11-12 20:13:27 +0000705 Scope *S,
Steve Naroff80175062007-09-28 22:22:11 +0000706 IdentifierInfo *receivingClassName, Selector Sel,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000707 SourceLocation lbrac, SourceLocation rbrac,
708 ExprTy **ArgExprs, unsigned NumArgs);
Steve Narofff73590d2007-09-27 14:38:14 +0000709
710 // ActOnInstanceMessage - used for both unary and keyword messages.
711 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000712 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +0000713 virtual ExprResult ActOnInstanceMessage(
Steve Naroff80175062007-09-28 22:22:11 +0000714 ExprTy *receiver, Selector Sel,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000715 SourceLocation lbrac, SourceLocation rbrac,
716 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff26c8ea52007-03-21 21:08:52 +0000717private:
Chris Lattnera65e1f32008-01-16 19:17:22 +0000718 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
719 /// cast. If there is already an implicit cast, merge into the existing one.
720 void ImpCastExprToType(Expr *&Expr, QualType Type);
721
Steve Naroff71b59a92007-06-04 22:22:31 +0000722 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner08464942007-12-28 05:29:59 +0000723 // functions and arrays to their respective pointers (C99 6.3.2.1).
724 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3e113402008-05-27 03:33:27 +0000725
726 // UsualUnaryConversionType - Same as UsualUnaryConversions, but works
727 // on types instead of expressions
728 QualType UsualUnaryConversionType(QualType Ty);
Steve Naroff31090012007-07-16 21:54:35 +0000729
730 // DefaultFunctionArrayConversion - converts functions and arrays
731 // to their respective pointers (C99 6.3.2.1).
732 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000733
Steve Naroff0b661582007-08-28 23:30:39 +0000734 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
735 // do not have a prototype. Integer promotions are performed on each
736 // argument, and arguments that have type float are promoted to double.
Chris Lattner08464942007-12-28 05:29:59 +0000737 void DefaultArgumentPromotion(Expr *&Expr);
Steve Naroff0b661582007-08-28 23:30:39 +0000738
Steve Naroff71b59a92007-06-04 22:22:31 +0000739 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
740 // operands and then handles various conversions that are common to binary
741 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
742 // routine returns the first non-arithmetic type found. The client is
743 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000744 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
745 bool isCompAssign = false);
Chris Lattner940cfeb2008-01-04 18:22:42 +0000746
747 /// AssignConvertType - All of the 'assignment' semantic checks return this
748 /// enum to indicate whether the assignment was allowed. These checks are
749 /// done for simple assignments, as well as initialization, return from
750 /// function, argument passing, etc. The query is phrased in terms of a
751 /// source and destination type.
Chris Lattner9bad62c2008-01-04 18:04:52 +0000752 enum AssignConvertType {
Chris Lattner940cfeb2008-01-04 18:22:42 +0000753 /// Compatible - the types are compatible according to the standard.
Steve Naroff17f76e02007-05-03 21:03:48 +0000754 Compatible,
Chris Lattner940cfeb2008-01-04 18:22:42 +0000755
756 /// PointerToInt - The assignment converts a pointer to an int, which we
757 /// accept as an extension.
758 PointerToInt,
759
760 /// IntToPointer - The assignment converts an int to a pointer, which we
761 /// accept as an extension.
762 IntToPointer,
763
764 /// FunctionVoidPointer - The assignment is between a function pointer and
765 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner0a788432008-01-03 22:56:36 +0000766 FunctionVoidPointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +0000767
768 /// IncompatiblePointer - The assignment is between two pointers types that
769 /// are not compatible, but we accept them as an extension.
Steve Naroff1f4d7272007-05-11 04:00:31 +0000770 IncompatiblePointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +0000771
772 /// CompatiblePointerDiscardsQualifiers - The assignment discards
773 /// c/v/r qualifiers, which we accept as an extension.
774 CompatiblePointerDiscardsQualifiers,
775
776 /// Incompatible - We reject this conversion outright, it is invalid to
777 /// represent it in the AST.
778 Incompatible
Steve Naroff17f76e02007-05-03 21:03:48 +0000779 };
Chris Lattner9bad62c2008-01-04 18:04:52 +0000780
781 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
782 /// assignment conversion type specified by ConvTy. This returns true if the
783 /// conversion was invalid or false if the conversion was accepted.
784 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
785 SourceLocation Loc,
786 QualType DstType, QualType SrcType,
787 Expr *SrcExpr, const char *Flavor);
788
789 /// CheckAssignmentConstraints - Perform type checking for assignment,
790 /// argument passing, variable initialization, and function return values.
791 /// This routine is only used by the following two methods. C99 6.5.16.
792 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000793
Steve Naroff83895f72007-09-16 03:34:24 +0000794 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff66356bd2007-09-16 14:56:35 +0000795 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000796 // this routine performs the default function/array converions.
Chris Lattner9bad62c2008-01-04 18:04:52 +0000797 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
798 Expr *&rExpr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000799 // CheckCompoundAssignmentConstraints - Type check without performing any
800 // conversions. For compound assignments, the "Check...Operands" methods
801 // perform the necessary conversions.
Chris Lattner9bad62c2008-01-04 18:04:52 +0000802 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
803 QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000804
Steve Naroff98cf3e92007-06-06 18:38:38 +0000805 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner9bad62c2008-01-04 18:04:52 +0000806 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
807 QualType rhsType);
Steve Naroff9eb24652007-05-02 21:58:15 +0000808
Steve Naroff8eeeb132007-05-08 21:09:37 +0000809 /// the following "Check" methods will return a valid/converted QualType
810 /// or a null QualType (indicating an error diagnostic was issued).
811
Steve Naroff83895f72007-09-16 03:34:24 +0000812 /// type checking binary operators (subroutines of ActOnBinOp).
Chris Lattner5c11c412007-12-12 05:47:28 +0000813 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000814 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000815 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000816 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000817 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000818 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000819 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000820 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000821 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000822 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000823 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnerb620c342007-08-26 01:18:55 +0000824 inline QualType CheckCompareOperands( // C99 6.5.8/9
825 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000826 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000827 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000828 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +0000829 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +0000830 // CheckAssignmentOperands is used for both simple and compound assignment.
831 // For simple assignment, pass both expressions and a null converted type.
832 // For compound assignment, pass both expressions and the converted type.
833 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0c1c7ed2007-08-24 22:33:52 +0000834 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000835 inline QualType CheckCommaOperands( // C99 6.5.17
Steve Naroff7a5af782007-07-13 16:58:59 +0000836 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +0000837 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +0000838 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Nate Begeman191a6b12008-07-14 18:02:46 +0000839
840 /// type checking for vector binary operators.
841 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
842 inline QualType CheckVectorCompareOperands(Expr *&lex, Expr *&rx,
843 SourceLocation l, bool isRel);
Steve Naroff95af0132007-03-30 23:47:58 +0000844
Steve Naroff83895f72007-09-16 03:34:24 +0000845 /// type checking unary operators (subroutines of ActOnUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +0000846 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Steve Naroff71ce2e02007-05-18 22:53:50 +0000847 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
848 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
849 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
Chris Lattner3f375d02008-07-25 21:45:37 +0000850 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc,
851 const SourceRange &R, bool isSizeof);
Chris Lattner74ed76b2007-08-24 21:41:10 +0000852 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Narofff8fd09e2007-07-27 22:15:19 +0000853
854 /// type checking primary expressions.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000855 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Narofff8fd09e2007-07-27 22:15:19 +0000856 IdentifierInfo &Comp, SourceLocation CmpLoc);
857
Steve Naroff2fea1392007-09-02 02:04:30 +0000858 /// type checking declaration initializers (C99 6.7.8)
Steve Narofff8ecff22008-05-01 22:18:59 +0000859 friend class InitListChecker;
Steve Naroff98f72032008-01-10 22:15:12 +0000860 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType);
861 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
Steve Naroff98f72032008-01-10 22:15:12 +0000862 bool CheckForConstantInitializer(Expr *e, QualType t);
Eli Friedmand5a55bd2008-05-20 13:48:25 +0000863 bool CheckArithmeticConstantExpression(const Expr* e);
864 bool CheckAddressConstantExpression(const Expr* e);
865 bool CheckAddressConstantExpressionLValue(const Expr* e);
Steve Naroff91f78082007-12-10 22:44:33 +0000866
Steve Naroffaf2a0222008-01-22 00:55:40 +0000867 StringLiteral *IsStringLiteralInit(Expr *Init, QualType DeclType);
868 bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT);
869
Anders Carlsson24c59952007-11-27 07:16:40 +0000870 // CheckVectorCast - check type constraints for vectors.
871 // Since vectors are an extension, there are no C standard reference for this.
872 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonde71adf2007-11-27 05:51:55 +0000873 // returns true if the cast is invalid
874 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
875
Steve Naroff077c83b2007-10-16 23:12:48 +0000876 // returns true if there were any incompatible arguments.
877 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000878 ObjCMethodDecl *Method);
Steve Naroff077c83b2007-10-16 23:12:48 +0000879
Chris Lattnerfc1c44a2007-08-23 05:46:52 +0000880 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
881 /// the specified width and sign. If an overflow occurs, detect it and emit
882 /// the specified diagnostic.
883 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
884 unsigned NewWidth, bool NewSign,
885 SourceLocation Loc, unsigned DiagID);
886
Chris Lattner2a3569b2008-04-07 05:30:13 +0000887 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
888 bool ForCompare);
889
890
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000891 void InitBuiltinVaListType();
Eli Friedman149614b2008-06-03 21:01:11 +0000892
893 // Helper method to turn variable array types into
894 // constant array types in certain situations which would otherwise
895 // be errors
896 QualType TryFixInvalidVariablyModifiedType(QualType T);
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000897
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000898 //===--------------------------------------------------------------------===//
899 // Extra semantic analysis beyond the C type system
Chris Lattner08464942007-12-28 05:29:59 +0000900private:
Eli Friedmana1b4ed82008-05-14 19:38:39 +0000901 Action::ExprResult CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
Chris Lattner08464942007-12-28 05:29:59 +0000902 bool CheckBuiltinCFStringArgument(Expr* Arg);
903 bool SemaBuiltinVAStart(CallExpr *TheCall);
904 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedmanf8353032008-05-20 08:23:37 +0000905 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Eli Friedmana1b4ed82008-05-14 19:38:39 +0000906 Action::ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Daniel Dunbarb7257262008-07-21 22:59:13 +0000907 bool SemaBuiltinPrefetch(CallExpr *TheCall);
Chris Lattner08464942007-12-28 05:29:59 +0000908 void CheckPrintfArguments(CallExpr *TheCall,
909 bool HasVAListArg, unsigned format_idx);
Ted Kremenekcff94fa2007-08-17 16:46:58 +0000910 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
911 SourceLocation ReturnLoc);
Ted Kremenek43fb8b02007-11-25 00:58:00 +0000912 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000913};
914
Steve Narofff8ecff22008-05-01 22:18:59 +0000915class InitListChecker {
916 Sema *SemaRef;
917 bool hadError;
918
919 void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
920 unsigned &Index);
Steve Naroff125d73d2008-05-06 00:23:44 +0000921 void CheckExplicitInitList(InitListExpr *IList, QualType &T,
Steve Narofff8ecff22008-05-01 22:18:59 +0000922 unsigned &Index);
923
Eli Friedman23a9e312008-05-19 19:16:24 +0000924 void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
925 unsigned &Index);
926 void CheckSubElementType(InitListExpr *IList, QualType ElemType,
927 unsigned &Index);
Steve Narofff8ecff22008-05-01 22:18:59 +0000928 // FIXME: Does DeclType need to be a reference type?
929 void CheckScalarType(InitListExpr *IList, QualType &DeclType,
930 unsigned &Index);
931 void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index);
932 void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
Eli Friedman23a9e312008-05-19 19:16:24 +0000933 unsigned &Index);
Steve Narofff8ecff22008-05-01 22:18:59 +0000934 void CheckArrayType(InitListExpr *IList, QualType &DeclType, unsigned &Index);
935
936 int numArrayElements(QualType DeclType);
937 int numStructUnionElements(QualType DeclType);
938public:
939 InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
940 bool HadError() { return hadError; }
941};
942
Chris Lattner7cee11f2006-11-03 06:42:29 +0000943
944} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +0000945
946#endif