blob: 0dda082d7e3021af10e8099df9fa6699b4efda83 [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"
Chris Lattner7cee11f2006-11-03 06:42:29 +000019#include "clang/Parse/Action.h"
Steve Naroffd0bf5162007-11-12 03:44:46 +000020#include "clang/Parse/DeclSpec.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"
Chris Lattner7cee11f2006-11-03 06:42:29 +000024#include <vector>
Chris Lattnereaafe1222006-11-10 05:17:58 +000025#include <string>
Chris Lattner7cee11f2006-11-03 06:42:29 +000026
Chris Lattnerfc1c44a2007-08-23 05:46:52 +000027namespace llvm {
28 class APSInt;
29}
30
Chris Lattner7cee11f2006-11-03 06:42:29 +000031namespace clang {
Chris Lattnercb6a3822006-11-10 06:20:45 +000032 class ASTContext;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000033 class ASTConsumer;
Chris Lattner7cee11f2006-11-03 06:42:29 +000034 class Preprocessor;
35 class Decl;
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000036 class DeclContext;
Steve Naroff257520b2008-04-01 23:04:06 +000037 class NamedDecl;
Steve Naroff9324db12007-09-13 18:10:37 +000038 class ScopedDecl;
Steve Naroff78403362007-04-02 22:55:05 +000039 class Expr;
Steve Narofff33527a2007-09-02 15:34:30 +000040 class InitListExpr;
Chris Lattner08464942007-12-28 05:29:59 +000041 class CallExpr;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000042 class VarDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000043 class ParmVarDecl;
Chris Lattner01564d92007-01-27 19:27:06 +000044 class TypedefDecl;
45 class FunctionDecl;
Steve Naroffe5aa9be2007-04-05 22:36:20 +000046 class QualType;
Chris Lattner9cf21c52007-09-04 02:45:27 +000047 struct LangOptions;
Chris Lattner146762e2007-07-20 16:59:19 +000048 class Token;
Steve Naroff35d85152007-05-07 00:24:15 +000049 class IntegerLiteral;
Steve Naroffaf2a0222008-01-22 00:55:40 +000050 class StringLiteral;
Steve Naroff8eeeb132007-05-08 21:09:37 +000051 class ArrayType;
Chris Lattnere2473062007-05-28 06:28:18 +000052 class LabelStmt;
Anders Carlsson51873c22007-07-22 07:07:56 +000053 class SwitchStmt;
Nate Begemance4d7fc2008-04-18 23:10:10 +000054 class ExtVectorType;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000055 class TypedefDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000056 class ObjCInterfaceDecl;
Steve Naroff257520b2008-04-01 23:04:06 +000057 class ObjCCompatibleAliasDecl;
Ted Kremenek1b0ea822008-01-07 19:49:32 +000058 class ObjCProtocolDecl;
59 class ObjCImplementationDecl;
60 class ObjCCategoryImplDecl;
61 class ObjCCategoryDecl;
62 class ObjCIvarDecl;
63 class ObjCMethodDecl;
Fariborz Jahanian7cf18862008-05-01 00:03:38 +000064 class ObjCPropertyDecl;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000065
Chris Lattnercc67ec12006-11-09 06:54:47 +000066/// Sema - This implements semantic analysis and AST building for C.
67class Sema : public Action {
Steve Naroff38d31b42007-02-28 01:22:02 +000068 Preprocessor &PP;
Chris Lattnercb6a3822006-11-10 06:20:45 +000069 ASTContext &Context;
Chris Lattnerfe0e0af2008-02-06 00:46:58 +000070 ASTConsumer &Consumer;
Chris Lattner7cee11f2006-11-03 06:42:29 +000071
Chris Lattner229ce602006-11-21 01:21:07 +000072 /// CurFunctionDecl - If inside of a function body, this contains a pointer to
73 /// the function decl for the function being parsed.
74 FunctionDecl *CurFunctionDecl;
Steve Naroffe3d1ab22007-11-12 13:56:41 +000075
76 /// CurMethodDecl - If inside of a method body, this contains a pointer to
77 /// the method decl for the method being parsed.
Ted Kremenek1b0ea822008-01-07 19:49:32 +000078 ObjCMethodDecl *CurMethodDecl;
Chris Lattnerc5ffed42008-04-04 06:12:32 +000079
Chris Lattner0a5ff0d2008-04-06 04:47:34 +000080 DeclContext *CurContext;
Chris Lattnerc5ffed42008-04-04 06:12:32 +000081
Chris Lattnere2473062007-05-28 06:28:18 +000082 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
83 /// it (which acts like the label decl in some ways). Forward referenced
84 /// labels have a LabelStmt created for them with a null location & SubStmt.
Chris Lattner23b7eb62007-06-15 23:05:46 +000085 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
Anders Carlsson51873c22007-07-22 07:07:56 +000086
87 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000088
Nate Begemance4d7fc2008-04-18 23:10:10 +000089 /// ExtVectorDecls - This is a list all the extended vector types. This allows
90 /// us to associate a raw vector type with one of the ext_vector type names.
Steve Naroffddf5a1d2007-07-29 16:33:31 +000091 /// This is only necessary for issuing pretty diagnostics.
Nate Begemance4d7fc2008-04-18 23:10:10 +000092 llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
Chris Lattnerb87b1b32007-08-10 20:18:51 +000093
Ted Kremenek1b0ea822008-01-07 19:49:32 +000094 /// ObjCImplementations - Keep track of all of the classes with
Chris Lattneree2d8412007-10-07 01:13:46 +000095 /// @implementation's, so that we can emit errors on duplicates.
Ted Kremenek1b0ea822008-01-07 19:49:32 +000096 llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
Chris Lattneree2d8412007-10-07 01:13:46 +000097
Ted Kremenek1b0ea822008-01-07 19:49:32 +000098 /// ObjCProtocols - Keep track of all protocol declarations declared
Fariborz Jahanian06f84f52007-10-09 18:03:53 +000099 /// with @protocol keyword, so that we can emit errors on duplicates and
Chris Lattner516ca702007-10-09 18:18:24 +0000100 /// find the declarations when needed.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000101 llvm::DenseMap<IdentifierInfo*, ObjCProtocolDecl*> ObjCProtocols;
Steve Naroff77892752008-04-02 18:30:49 +0000102
103 /// ObjCInterfaceDecls - Keep track of all class declarations declared
104 /// with @interface, so that we can emit errors on duplicates and
105 /// find the declarations when needed.
106 typedef llvm::DenseMap<const IdentifierInfo*,
107 ObjCInterfaceDecl*> ObjCInterfaceDeclsTy;
108 ObjCInterfaceDeclsTy ObjCInterfaceDecls;
109
Steve Naroff257520b2008-04-01 23:04:06 +0000110 /// ObjCAliasDecls - Keep track of all class declarations declared
111 /// with @compatibility_alias, so that we can emit errors on duplicates and
112 /// find the declarations when needed. This construct is ancient and will
113 /// likely never be seen. Nevertheless, it is here for compatibility.
Steve Naroff9b94b172008-04-02 00:39:51 +0000114 typedef llvm::DenseMap<const IdentifierInfo*,
115 ObjCCompatibleAliasDecl*> ObjCAliasTy;
Steve Naroff257520b2008-04-01 23:04:06 +0000116 ObjCAliasTy ObjCAliasDecls;
Steve Naroff77892752008-04-02 18:30:49 +0000117
Chris Lattnerc5c95b52008-04-11 07:00:53 +0000118 IdentifierResolver IdResolver;
119
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000120 // Enum values used by KnownFunctionIDs (see below).
121 enum {
122 id_printf,
123 id_fprintf,
124 id_sprintf,
125 id_snprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000126 id_asprintf,
Ted Kremenek34f664d2008-06-16 18:00:42 +0000127 id_NSLog,
Ted Kremenekcfc94192007-08-10 21:13:51 +0000128 id_vsnprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000129 id_vasprintf,
130 id_vfprintf,
131 id_vsprintf,
132 id_vprintf,
133 id_num_known_functions
134 };
135
136 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
137 /// of known functions used by the semantic analysis to do various
138 /// kinds of checking (e.g. checking format string errors in printf calls).
139 /// This list is populated upon the creation of a Sema object.
140 IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
141
Steve Naroff93eb5f12007-10-10 17:32:04 +0000142 /// Translation Unit Scope - useful to Objective-C actions that need
143 /// to lookup file scope declarations in the "ordinary" C decl namespace.
144 /// For example, user-defined classes, built-in "id" type, etc.
Steve Naroffc62adb62007-10-09 22:01:59 +0000145 Scope *TUScope;
Steve Naroff7f549f12007-10-10 21:53:07 +0000146
Steve Naroff5811baf2007-10-14 00:58:41 +0000147 /// ObjCMethodList - a linked list of methods with different signatures.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000148 struct ObjCMethodList {
149 ObjCMethodDecl *Method;
150 ObjCMethodList *Next;
Steve Naroff5811baf2007-10-14 00:58:41 +0000151
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000152 ObjCMethodList() {
Steve Naroff5811baf2007-10-14 00:58:41 +0000153 Method = 0;
154 Next = 0;
155 }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000156 ObjCMethodList(ObjCMethodDecl *M, ObjCMethodList *C) {
Steve Naroff5811baf2007-10-14 00:58:41 +0000157 Method = M;
158 Next = C;
159 }
160 };
161 /// Instance/Factory Method Pools - allows efficient lookup when typechecking
162 /// messages to "id". We need to maintain a list, since selectors can have
163 /// differing signatures across classes. In Cocoa, this happens to be
164 /// extremely uncommon (only 1% of selectors are "overloaded").
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000165 llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
166 llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
Chris Lattner7cee11f2006-11-03 06:42:29 +0000167public:
Chris Lattnerfe0e0af2008-02-06 00:46:58 +0000168 Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000169
Chris Lattnerac18be92006-11-20 06:49:47 +0000170 const LangOptions &getLangOptions() const;
171
Steve Naroff71ce2e02007-05-18 22:53:50 +0000172 /// The primitive diagnostic helpers - always returns true, which simplifies
173 /// error handling (i.e. less code).
Chris Lattnerd6647d32007-05-16 17:56:50 +0000174 bool Diag(SourceLocation Loc, unsigned DiagID);
175 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
176 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
177 const std::string &Msg2);
Steve Naroff71ce2e02007-05-18 22:53:50 +0000178
179 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
180 bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
181 bool Diag(SourceLocation Loc, unsigned DiagID,
182 SourceRange R1, SourceRange R2);
183 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
184 SourceRange R1);
185 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
186 SourceRange R1, SourceRange R2);
187 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
188 const std::string &Msg2, SourceRange R1);
Chris Lattner816dea22008-01-03 23:38:43 +0000189 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
190 const std::string &Msg2, const std::string &Msg3, SourceRange R1);
Steve Naroff71ce2e02007-05-18 22:53:50 +0000191 bool Diag(SourceLocation Loc, unsigned DiagID,
192 const std::string &Msg1, const std::string &Msg2,
193 SourceRange R1, SourceRange R2);
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000194
Chris Lattner57c523f2007-08-31 04:53:24 +0000195 virtual void DeleteExpr(ExprTy *E);
196 virtual void DeleteStmt(StmtTy *S);
197
Chris Lattner7cee11f2006-11-03 06:42:29 +0000198 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000199 // Type Analysis / Processing: SemaType.cpp.
200 //
Chris Lattner4b413ea2008-06-26 06:27:57 +0000201 QualType ConvertDeclSpecToType(const DeclSpec &DS);
202 void ProcessTypeAttributes(QualType &Result, const AttributeList *AL);
Steve Naroffe5aa9be2007-04-05 22:36:20 +0000203 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000204
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000205
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000206 QualType ObjCGetTypeForMethodDefinition(DeclTy *D);
Fariborz Jahanian56ff1462007-11-08 23:49:49 +0000207
208
Steve Naroff30d242c2007-09-15 18:49:24 +0000209 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Steve Naroff26c8ea52007-03-21 21:08:52 +0000210private:
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000211 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000212 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000213 //
Steve Naroff2fc93f52008-04-02 14:35:35 +0000214 virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S);
Steve Naroff30d242c2007-09-15 18:49:24 +0000215 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000216 virtual DeclTy *ActOnParamDeclarator(Scope *S, Declarator &D);
217 virtual void ActOnParamDefaultArgument(DeclTy *param,
218 SourceLocation EqualLoc,
219 ExprTy *defarg);
Steve Naroff61091402007-09-12 14:07:44 +0000220 void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
Chris Lattner776fac82007-06-09 00:53:06 +0000221 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
222
Chris Lattnera55a2cc2007-10-09 17:14:05 +0000223 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D);
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +0000224 // Until 'real' implementation is in place, override both
225 // 'ActOnStartOfFunctionDef' to satisfy the compiler.
226 virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, DeclTy *D) { return D; }
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000227 virtual void ObjCActOnStartOfMethodDef(Scope *S, DeclTy *D);
Steve Naroffb313fc32007-11-11 23:20:51 +0000228
229 virtual DeclTy *ActOnFinishFunctionBody(DeclTy *Decl, StmtTy *Body);
Chris Lattner38376f12008-01-12 07:05:38 +0000230 virtual DeclTy *ActOnLinkageSpec(SourceLocation Loc, SourceLocation LBrace,
Nate Begeman7dd8e722008-02-20 22:57:40 +0000231 SourceLocation RBrace, const char *Lang,
232 unsigned StrSize, DeclTy *D);
Anders Carlsson5c6c0592008-02-08 00:33:21 +0000233 virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *expr);
234
Steve Naroffc62adb62007-10-09 22:01:59 +0000235 /// Scope actions.
236 virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
237 virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000238
Chris Lattner200bdc32006-11-19 02:43:37 +0000239 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
240 /// no declarator (e.g. "struct foo;") is parsed.
241 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
242
Steve Naroff30d242c2007-09-15 18:49:24 +0000243 virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
Chris Lattnerf34c4da2007-01-23 04:08:05 +0000244 SourceLocation KWLoc, IdentifierInfo *Name,
Steve Naroffb3096442007-06-09 03:47:53 +0000245 SourceLocation NameLoc, AttributeList *Attr);
Chris Lattner535b8302008-06-21 19:39:06 +0000246 virtual void ActOnDefs(Scope *S, SourceLocation DeclStart, IdentifierInfo
247 *ClassName, llvm::SmallVector<DeclTy*, 16> &Decls);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000248 virtual DeclTy *ActOnField(Scope *S, SourceLocation DeclStart,
Chris Lattner1300fb92007-01-23 23:42:53 +0000249 Declarator &D, ExprTy *BitfieldWidth);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000250
251 virtual DeclTy *ActOnIvar(Scope *S, SourceLocation DeclStart,
252 Declarator &D, ExprTy *BitfieldWidth,
Fariborz Jahanian96376742008-04-11 16:55:42 +0000253 tok::ObjCKeywordKind visibility);
Fariborz Jahaniande615832008-04-10 23:32:45 +0000254
Steve Naroff2e688fd2007-09-14 23:09:53 +0000255 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian343f7092007-09-29 00:54:24 +0000256 virtual void ActOnFields(Scope* S,
Steve Naroff33a1e802007-10-29 21:38:07 +0000257 SourceLocation RecLoc, DeclTy *TagDecl,
258 DeclTy **Fields, unsigned NumFields,
Fariborz Jahaniande615832008-04-10 23:32:45 +0000259 SourceLocation LBrac, SourceLocation RBrac);
Steve Naroff30d242c2007-09-15 18:49:24 +0000260 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000261 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000262 SourceLocation IdLoc, IdentifierInfo *Id,
263 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff30d242c2007-09-15 18:49:24 +0000264 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000265 DeclTy **Elements, unsigned NumElements);
Steve Naroff3273c222007-03-14 21:52:03 +0000266private:
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000267 /// Set the current declaration context until it gets popped.
Chris Lattnerbec41342008-04-22 18:39:57 +0000268 void PushDeclContext(DeclContext *DC);
Chris Lattner0a5ff0d2008-04-06 04:47:34 +0000269 void PopDeclContext();
Chris Lattnerc5ffed42008-04-04 06:12:32 +0000270
Argyrios Kyrtzidisb8a49202008-04-12 00:47:19 +0000271 /// Add this decl to the scope shadowed decl chains.
272 void PushOnScopeChains(NamedDecl *D, Scope *S);
273
Chris Lattnerefedd9e2008-02-21 01:07:18 +0000274 /// Subroutines of ActOnDeclarator().
Chris Lattner07b201d2007-11-14 06:34:38 +0000275 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
276 ScopedDecl *LastDecl);
Steve Naroff257520b2008-04-01 23:04:06 +0000277 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
Douglas Gregor89f238c2008-04-21 02:02:58 +0000278 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old,
279 bool &Redeclaration);
Steve Naroff257520b2008-04-01 23:04:06 +0000280 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000281 FunctionDecl *MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old);
282
283 /// Helpers for dealing with function parameters
284 bool CheckParmsForFunctionDef(FunctionDecl *FD);
Chris Lattner5696e7b2008-06-17 18:05:57 +0000285 ImplicitParamDecl *CreateImplicitParameter(Scope *S, IdentifierInfo *Id,
Chris Lattneraa9c7ae2008-04-08 04:40:51 +0000286 SourceLocation IdLoc, QualType Type);
287 void CheckCXXDefaultArguments(FunctionDecl *FD);
Douglas Gregorcaa8ace2008-05-07 04:49:29 +0000288 void CheckExtraCXXDefaultArguments(Declarator &D);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000289
Steve Naroff3273c222007-03-14 21:52:03 +0000290 /// More parsing and symbol table subroutines...
Steve Naroff2fc93f52008-04-02 14:35:35 +0000291 Decl *LookupDecl(const IdentifierInfo *II, unsigned NSI, Scope *S,
292 bool enableLazyBuiltinCreation = true);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000293 ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Steve Naroff2fc93f52008-04-02 14:35:35 +0000294 ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
295 Scope *S);
Steve Naroff2f742082007-09-16 16:16:00 +0000296 ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Steve Naroff3273c222007-03-14 21:52:03 +0000297 Scope *S);
Steve Naroffa8fd9732007-06-11 00:35:03 +0000298 // Decl attributes - this routine is the top level dispatcher.
Chris Lattnercf31de32008-06-26 06:49:43 +0000299 void HandleDeclAttributes(Decl *New, const AttributeList *DeclSpecAttrs,
300 const AttributeList *DeclaratorAttrs);
301 void HandleDeclAttribute(Decl *New, const AttributeList *rawAttr);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000302
303 /// HandleAddressSpaceTypeAttribute - this attribute is only applicable to
304 /// objects without automatic storage duration.
305 /// The raw attribute contains 1 argument, the id of the address space
306 /// for the type.
307 QualType HandleAddressSpaceTypeAttribute(QualType curType,
Chris Lattner4b413ea2008-06-26 06:27:57 +0000308 const AttributeList *rawAttr);
Eli Friedman3e113402008-05-27 03:33:27 +0000309
Chris Lattneracbc2d22008-06-27 22:18:37 +0000310 /// HandleModeAttribute - this attribute modifies the width of a decl with
Eli Friedman3e113402008-05-27 03:33:27 +0000311 /// primitive type. Note that this is a variable attribute, and not
312 /// a type attribute.
Chris Lattneracbc2d22008-06-27 22:18:37 +0000313 void HandleModeAttribute(Decl *d, const AttributeList &Attr);
Christopher Lamb025b5fb2008-02-04 02:31:56 +0000314
Steve Naroffa8fd9732007-06-11 00:35:03 +0000315 // HandleVectorTypeAttribute - this attribute is only applicable to
316 // integral and float scalars, although arrays, pointers, and function
317 // return values are allowed in conjunction with this construct. Aggregates
318 // with this attribute are invalid, even if they are of the same size as a
319 // corresponding scalar.
320 // The raw attribute should contain precisely 1 argument, the vector size
321 // for the variable, measured in bytes. If curType and rawAttr are well
322 // formed, this routine will return a new vector type.
Chris Lattnercf31de32008-06-26 06:49:43 +0000323 QualType HandleVectorTypeAttribute(QualType curType,
324 const AttributeList *rawAttr);
325 void HandleExtVectorTypeAttribute(TypedefDecl *d,
326 const AttributeList *rawAttr);
Chris Lattner1300fb92007-01-23 23:42:53 +0000327
Chris Lattnercf31de32008-06-26 06:49:43 +0000328 void HandleAlignedAttribute(Decl *d, const AttributeList *rawAttr);
329 void HandleAliasAttribute(Decl *d, const AttributeList *rawAttr);
330 void HandlePackedAttribute(Decl *d, const AttributeList *rawAttr);
331 void HandleAnnotateAttribute(Decl *d, const AttributeList *rawAttr);
332 void HandleNoReturnAttribute(Decl *d, const AttributeList *rawAttr);
333 void HandleDeprecatedAttribute(Decl *d, const AttributeList *rawAttr);
334 void HandleWeakAttribute(Decl *d, const AttributeList *rawAttr);
335 void HandleDLLImportAttribute(Decl *d, const AttributeList *rawAttr);
336 void HandleDLLExportAttribute(Decl *d, const AttributeList *rawAttr);
337 void HandleVisibilityAttribute(Decl *d, const AttributeList *rawAttr);
338 void HandleNothrowAttribute(Decl *d, const AttributeList *rawAttr);
339 void HandleFormatAttribute(Decl *d, const AttributeList *rawAttr);
340 void HandleStdCallAttribute(Decl *d, const AttributeList *rawAttr);
341 void HandleFastCallAttribute(Decl *d, const AttributeList *rawAttr);
342 void HandleTransparentUnionAttribute(Decl *d, const AttributeList *rawAttr);
Anders Carlsson28e71082008-02-16 00:29:18 +0000343
Steve Naroff15833ed2008-02-10 21:38:56 +0000344 void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
345 bool &IncompleteImpl);
346
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000347 /// CheckProtocolMethodDefs - This routine checks unimpletented methods
348 /// Declared in protocol, and those referenced by it.
Steve Naroffa36992242008-02-08 22:06:17 +0000349 void CheckProtocolMethodDefs(SourceLocation ImpLoc,
350 ObjCProtocolDecl *PDecl,
Fariborz Jahanianadf84f32007-10-02 20:06:01 +0000351 bool& IncompleteImpl,
Steve Naroff71c3c1c2007-10-08 21:05:34 +0000352 const llvm::DenseSet<Selector> &InsMap,
Chris Lattnerdadc7622007-10-05 20:15:24 +0000353 const llvm::DenseSet<Selector> &ClsMap);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000354
Steve Naroffd1741552007-10-02 21:43:37 +0000355 /// CheckImplementationIvars - This routine checks if the instance variables
356 /// listed in the implelementation match those listed in the interface.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000357 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
358 ObjCIvarDecl **Fields, unsigned nIvars,
Steve Naroff15833ed2008-02-10 21:38:56 +0000359 SourceLocation Loc);
Steve Naroffd1741552007-10-02 21:43:37 +0000360
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000361 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
362 /// remains unimplemented in the @implementation class.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000363 void ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
364 ObjCInterfaceDecl* IDecl);
Fariborz Jahanianec7b3332007-09-29 17:14:55 +0000365
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +0000366 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
367 /// category interface is implemented in the category @implementation.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000368 void ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
369 ObjCCategoryDecl *CatClassDecl);
Fariborz Jahanian458f7112007-10-05 18:00:57 +0000370 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns
371 /// true, or false, accordingly.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000372 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
373 const ObjCMethodDecl *PrevMethod);
Steve Naroff7f549f12007-10-10 21:53:07 +0000374
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000375 /// isBuiltinObjCType - Returns true of the type is "id", "SEL", "Class"
Fariborz Jahanian2bbd03a2007-12-07 00:18:54 +0000376 /// or "Protocol".
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000377 bool isBuiltinObjCType(TypedefDecl *TD);
Fariborz Jahanian775d5d02008-01-04 00:27:46 +0000378
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000379 /// isObjCObjectPointerType - Returns true if type is an objective-c pointer
Fariborz Jahanian775d5d02008-01-04 00:27:46 +0000380 /// to an object type; such as "id", "Class", Intf*, id<P>, etc.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000381 bool isObjCObjectPointerType(QualType type) const;
Anders Carlssonf56a7ae2007-10-31 02:53:19 +0000382
Steve Naroff5811baf2007-10-14 00:58:41 +0000383 /// AddInstanceMethodToGlobalPool - All instance methods in a translation
384 /// unit are added to a global pool. This allows us to efficiently associate
385 /// a selector with a method declaraation for purposes of typechecking
386 /// messages sent to "id" (where the class of the object is unknown).
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000387 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method);
Steve Naroff5811baf2007-10-14 00:58:41 +0000388
389 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods.
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000390 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000391 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000392 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +0000393public:
Steve Naroff66356bd2007-09-16 14:56:35 +0000394 virtual StmtResult ActOnExprStmt(ExprTy *Expr);
Chris Lattner1ec5f562007-06-27 05:38:08 +0000395
Steve Naroff66356bd2007-09-16 14:56:35 +0000396 virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
397 virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnercac27a52007-08-31 21:49:55 +0000398 StmtTy **Elts, unsigned NumElts,
399 bool isStmtExpr);
Chris Lattner2e232092008-03-13 06:29:04 +0000400 virtual StmtResult ActOnDeclStmt(DeclTy *Decl, SourceLocation StartLoc,
401 SourceLocation EndLoc);
Steve Naroff66356bd2007-09-16 14:56:35 +0000402 virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
Chris Lattner6c0ff132006-11-05 00:19:50 +0000403 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
404 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff66356bd2007-09-16 14:56:35 +0000405 virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
Chris Lattner46eeb222007-07-18 02:28:47 +0000406 SourceLocation ColonLoc, StmtTy *SubStmt,
407 Scope *CurScope);
Steve Naroff66356bd2007-09-16 14:56:35 +0000408 virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Chris Lattner6c0ff132006-11-05 00:19:50 +0000409 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff66356bd2007-09-16 14:56:35 +0000410 virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000411 StmtTy *ThenVal, SourceLocation ElseLoc,
412 StmtTy *ElseVal);
Steve Naroff66356bd2007-09-16 14:56:35 +0000413 virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
Chris Lattnerdadc7622007-10-05 20:15:24 +0000414 virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
415 StmtTy *Switch, ExprTy *Body);
Steve Naroff66356bd2007-09-16 14:56:35 +0000416 virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
Chris Lattner85ed8732006-11-04 20:40:44 +0000417 StmtTy *Body);
Steve Naroff66356bd2007-09-16 14:56:35 +0000418 virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner85ed8732006-11-04 20:40:44 +0000419 SourceLocation WhileLoc, ExprTy *Cond);
420
Steve Naroff66356bd2007-09-16 14:56:35 +0000421 virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
Chris Lattner71e23ce2006-11-04 20:18:38 +0000422 SourceLocation LParenLoc,
423 StmtTy *First, ExprTy *Second, ExprTy *Third,
424 SourceLocation RParenLoc, StmtTy *Body);
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000425 virtual StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc,
Fariborz Jahanian732b8c22008-01-03 17:55:25 +0000426 SourceLocation LParenLoc,
427 StmtTy *First, ExprTy *Second,
428 SourceLocation RParenLoc, StmtTy *Body);
429
Steve Naroff66356bd2007-09-16 14:56:35 +0000430 virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
Chris Lattner16976d32006-11-05 01:46:01 +0000431 SourceLocation LabelLoc,
432 IdentifierInfo *LabelII);
Steve Naroff66356bd2007-09-16 14:56:35 +0000433 virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattner16976d32006-11-05 01:46:01 +0000434 SourceLocation StarLoc,
435 ExprTy *DestExp);
Steve Naroff66356bd2007-09-16 14:56:35 +0000436 virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Chris Lattnereaafe1222006-11-10 05:17:58 +0000437 Scope *CurScope);
Steve Naroff66356bd2007-09-16 14:56:35 +0000438 virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Chris Lattner71e23ce2006-11-04 20:18:38 +0000439
Steve Naroff66356bd2007-09-16 14:56:35 +0000440 virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000441 ExprTy *RetValExp);
442
Anders Carlsson81a5a692007-11-20 19:21:03 +0000443 virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
Anders Carlsson19fe1162008-02-05 23:03:50 +0000444 bool IsSimple,
Anders Carlsson660bdd12007-11-23 23:12:25 +0000445 bool IsVolatile,
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000446 unsigned NumOutputs,
447 unsigned NumInputs,
448 std::string *Names,
449 ExprTy **Constraints,
450 ExprTy **Exprs,
Anders Carlsson81a5a692007-11-20 19:21:03 +0000451 ExprTy *AsmString,
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000452 unsigned NumClobbers,
453 ExprTy **Clobbers,
Chris Lattner73c56c02007-10-29 04:04:16 +0000454 SourceLocation RParenLoc);
455
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000456 virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
Fariborz Jahanian9e63b982007-11-01 23:59:59 +0000457 SourceLocation RParen, StmtTy *Parm,
458 StmtTy *Body, StmtTy *CatchList);
459
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000460 virtual StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc,
Fariborz Jahanian71234d82007-11-02 00:18:53 +0000461 StmtTy *Body);
462
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000463 virtual StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc,
Fariborz Jahanianf859ef22007-11-02 15:39:31 +0000464 StmtTy *Try,
465 StmtTy *Catch, StmtTy *Finally);
466
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000467 virtual StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc,
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000468 StmtTy *Throw);
Fariborz Jahanian48085b82008-01-29 19:14:59 +0000469 virtual StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc,
470 ExprTy *SynchExpr,
471 StmtTy *SynchBody);
Fariborz Jahanianadfbbc32007-11-07 02:00:49 +0000472
Chris Lattner7cee11f2006-11-03 06:42:29 +0000473 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000474 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000475
476 // Primary Expressions.
Steve Naroff30d242c2007-09-15 18:49:24 +0000477 virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
Chris Lattnerac18be92006-11-20 06:49:47 +0000478 IdentifierInfo &II,
479 bool HasTrailingLParen);
Steve Naroff83895f72007-09-16 03:34:24 +0000480 virtual ExprResult ActOnPreDefinedExpr(SourceLocation Loc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000481 tok::TokenKind Kind);
Steve Naroff83895f72007-09-16 03:34:24 +0000482 virtual ExprResult ActOnNumericConstant(const Token &);
483 virtual ExprResult ActOnCharacterConstant(const Token &);
484 virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000485 ExprTy *Val);
Chris Lattner697e5d62006-11-09 06:32:27 +0000486
Steve Naroff83895f72007-09-16 03:34:24 +0000487 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +0000488 /// fragments (e.g. "foo" "bar" L"baz").
Steve Naroff83895f72007-09-16 03:34:24 +0000489 virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
Chris Lattner697e5d62006-11-09 06:32:27 +0000490
Chris Lattner7cee11f2006-11-03 06:42:29 +0000491 // Binary/Unary Operators. 'Tok' is the token for the operator.
Steve Naroff83895f72007-09-16 03:34:24 +0000492 virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000493 ExprTy *Input);
494 virtual ExprResult
Steve Naroff83895f72007-09-16 03:34:24 +0000495 ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000496 SourceLocation LParenLoc, TypeTy *Ty,
497 SourceLocation RParenLoc);
498
Steve Naroff83895f72007-09-16 03:34:24 +0000499 virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000500 tok::TokenKind Kind, ExprTy *Input);
501
Steve Naroff83895f72007-09-16 03:34:24 +0000502 virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000503 ExprTy *Idx, SourceLocation RLoc);
Steve Naroff83895f72007-09-16 03:34:24 +0000504 virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000505 tok::TokenKind OpKind,
506 SourceLocation MemberLoc,
507 IdentifierInfo &Member);
508
Steve Naroff83895f72007-09-16 03:34:24 +0000509 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000510 /// This provides the location of the left/right parens and a list of comma
511 /// locations.
Steve Naroff83895f72007-09-16 03:34:24 +0000512 virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000513 ExprTy **Args, unsigned NumArgs,
514 SourceLocation *CommaLocs,
515 SourceLocation RParenLoc);
516
Steve Naroff83895f72007-09-16 03:34:24 +0000517 virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000518 SourceLocation RParenLoc, ExprTy *Op);
Steve Narofffbd09832007-07-19 01:06:55 +0000519
Steve Naroff83895f72007-09-16 03:34:24 +0000520 virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
Steve Narofffbd09832007-07-19 01:06:55 +0000521 SourceLocation RParenLoc, ExprTy *Op);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000522
Steve Naroff83895f72007-09-16 03:34:24 +0000523 virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
Steve Narofffbd09832007-07-19 01:06:55 +0000524 ExprTy **InitList, unsigned NumInit,
525 SourceLocation RParenLoc);
526
Steve Naroff83895f72007-09-16 03:34:24 +0000527 virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000528 ExprTy *LHS,ExprTy *RHS);
529
Steve Naroff83895f72007-09-16 03:34:24 +0000530 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner7cee11f2006-11-03 06:42:29 +0000531 /// in the case of a the GNU conditional expr extension.
Steve Naroff83895f72007-09-16 03:34:24 +0000532 virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000533 SourceLocation ColonLoc,
534 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
Chris Lattner29375652006-12-04 18:06:35 +0000535
Steve Naroff66356bd2007-09-16 14:56:35 +0000536 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
537 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattnereefa10e2007-05-28 06:56:27 +0000538 IdentifierInfo *LabelII);
539
Steve Naroff66356bd2007-09-16 14:56:35 +0000540 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner366727f2007-07-24 16:58:17 +0000541 SourceLocation RPLoc); // "({..})"
Chris Lattnerf17bd422007-08-30 17:45:32 +0000542
543 /// __builtin_offsetof(type, a.b[123][456].c)
Steve Naroff66356bd2007-09-16 14:56:35 +0000544 virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
Chris Lattnerf17bd422007-08-30 17:45:32 +0000545 SourceLocation TypeLoc, TypeTy *Arg1,
546 OffsetOfComponent *CompPtr,
547 unsigned NumComponents,
548 SourceLocation RParenLoc);
549
Steve Naroff78864672007-08-01 22:05:33 +0000550 // __builtin_types_compatible_p(type1, type2)
Steve Naroff66356bd2007-09-16 14:56:35 +0000551 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +0000552 TypeTy *arg1, TypeTy *arg2,
553 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +0000554
555 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff66356bd2007-09-16 14:56:35 +0000556 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff9efdabc2007-08-03 21:21:27 +0000557 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
558 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +0000559
Nate Begeman1e36a852008-01-17 17:46:27 +0000560 // __builtin_overload(...)
561 virtual ExprResult ActOnOverloadExpr(ExprTy **Args, unsigned NumArgs,
562 SourceLocation *CommaLocs,
563 SourceLocation BuiltinLoc,
564 SourceLocation RParenLoc);
Nate Begeman0a6192c2008-03-07 20:04:22 +0000565
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000566 // __builtin_va_arg(expr, type)
567 virtual ExprResult ActOnVAArg(SourceLocation BuiltinLoc,
568 ExprTy *expr, TypeTy *type,
569 SourceLocation RPLoc);
570
Argyrios Kyrtzidis08114892008-04-27 13:50:30 +0000571 // Act on C++ namespaces
572 virtual DeclTy *ActOnStartNamespaceDef(Scope *S, SourceLocation IdentLoc,
573 IdentifierInfo *Ident,
574 SourceLocation LBrace);
575 virtual void ActOnFinishNamespaceDef(DeclTy *Dcl, SourceLocation RBrace);
576
Steve Naroff66356bd2007-09-16 14:56:35 +0000577 /// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
578 virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
Chris Lattner29375652006-12-04 18:06:35 +0000579 SourceLocation LAngleBracketLoc, TypeTy *Ty,
580 SourceLocation RAngleBracketLoc,
581 SourceLocation LParenLoc, ExprTy *E,
582 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +0000583
Steve Naroff66356bd2007-09-16 14:56:35 +0000584 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
585 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +0000586 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +0000587
Chris Lattnerb7e656b2008-02-26 00:51:44 +0000588 //// ActOnCXXThrow - Parse throw expressions.
589 virtual ExprResult ActOnCXXThrow(SourceLocation OpLoc,
590 ExprTy *expr);
591
Anders Carlsson76f4a902007-08-21 17:43:55 +0000592 // ParseObjCStringLiteral - Parse Objective-C string literals.
Chris Lattnere002fbe2007-12-12 01:04:12 +0000593 virtual ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
594 ExprTy **Strings,
595 unsigned NumStrings);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000596 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
Chris Lattner37390be2007-10-16 22:51:17 +0000597 SourceLocation EncodeLoc,
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000598 SourceLocation LParenLoc,
599 TypeTy *Ty,
600 SourceLocation RParenLoc);
601
Fariborz Jahanian4bef4622007-10-16 20:40:23 +0000602 // ParseObjCSelectorExpression - Build selector expression for @selector
603 virtual ExprResult ParseObjCSelectorExpression(Selector Sel,
604 SourceLocation AtLoc,
Fariborz Jahanian6bd1d612007-10-16 23:21:02 +0000605 SourceLocation SelLoc,
Fariborz Jahanian4bef4622007-10-16 20:40:23 +0000606 SourceLocation LParenLoc,
607 SourceLocation RParenLoc);
608
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +0000609 // ParseObjCProtocolExpression - Build protocol expression for @protocol
610 virtual ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName,
611 SourceLocation AtLoc,
612 SourceLocation ProtoLoc,
613 SourceLocation LParenLoc,
614 SourceLocation RParenLoc);
Douglas Gregor556877c2008-04-13 21:30:24 +0000615
616 //===--------------------------------------------------------------------===//
617 // C++ Classes
618 //
619 /// ActOnBaseSpecifier - Parsed a base specifier
620 virtual void ActOnBaseSpecifier(DeclTy *classdecl, SourceRange SpecifierRange,
621 bool Virtual, AccessSpecifier Access,
622 DeclTy *basetype, SourceLocation BaseLoc);
Fariborz Jahaniana32aaef2007-10-17 16:58:11 +0000623
Douglas Gregor556877c2008-04-13 21:30:24 +0000624
Steve Naroff09bf8152007-09-06 21:24:23 +0000625 // Objective-C declarations.
Steve Naroff93eb5f12007-10-10 17:32:04 +0000626 virtual DeclTy *ActOnStartClassInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +0000627 SourceLocation AtInterafceLoc,
Steve Naroff09bf8152007-09-06 21:24:23 +0000628 IdentifierInfo *ClassName, SourceLocation ClassLoc,
629 IdentifierInfo *SuperName, SourceLocation SuperLoc,
630 IdentifierInfo **ProtocolNames, unsigned NumProtocols,
Steve Naroffc5484042007-10-30 02:23:23 +0000631 SourceLocation EndProtoLoc, AttributeList *AttrList);
Fariborz Jahanian49c64252007-10-11 23:42:27 +0000632
633 virtual DeclTy *ActOnCompatiblityAlias(
634 SourceLocation AtCompatibilityAliasLoc,
635 IdentifierInfo *AliasName, SourceLocation AliasLocation,
636 IdentifierInfo *ClassName, SourceLocation ClassLocation);
Steve Naroff09bf8152007-09-06 21:24:23 +0000637
Steve Naroff93eb5f12007-10-10 17:32:04 +0000638 virtual DeclTy *ActOnStartProtocolInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +0000639 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian39d641f2007-09-17 21:07:36 +0000640 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
Steve Naroffc5484042007-10-30 02:23:23 +0000641 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs,
642 SourceLocation EndProtoLoc);
Fariborz Jahanian39d641f2007-09-17 21:07:36 +0000643
Steve Naroff93eb5f12007-10-10 17:32:04 +0000644 virtual DeclTy *ActOnStartCategoryInterface(
Nate Begeman7dd8e722008-02-20 22:57:40 +0000645 SourceLocation AtInterfaceLoc,
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +0000646 IdentifierInfo *ClassName, SourceLocation ClassLoc,
647 IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
Steve Naroff5448cf62007-10-30 13:30:57 +0000648 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs,
649 SourceLocation EndProtoLoc);
Fariborz Jahanian867a7eb2007-09-18 20:26:58 +0000650
Steve Naroff93eb5f12007-10-10 17:32:04 +0000651 virtual DeclTy *ActOnStartClassImplementation(
Nate Begeman7dd8e722008-02-20 22:57:40 +0000652 SourceLocation AtClassImplLoc,
Fariborz Jahanianbfe13c52007-09-25 18:38:09 +0000653 IdentifierInfo *ClassName, SourceLocation ClassLoc,
654 IdentifierInfo *SuperClassname,
655 SourceLocation SuperClassLoc);
656
Steve Naroff93eb5f12007-10-10 17:32:04 +0000657 virtual DeclTy *ActOnStartCategoryImplementation(
Fariborz Jahanian89b8ef92007-10-02 16:38:50 +0000658 SourceLocation AtCatImplLoc,
659 IdentifierInfo *ClassName,
660 SourceLocation ClassLoc,
661 IdentifierInfo *CatName,
662 SourceLocation CatLoc);
663
Steve Naroff93eb5f12007-10-10 17:32:04 +0000664 virtual DeclTy *ActOnForwardClassDeclaration(SourceLocation Loc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +0000665 IdentifierInfo **IdentList,
666 unsigned NumElts);
Fariborz Jahanian876e27d2007-09-21 15:40:54 +0000667
Steve Naroff93eb5f12007-10-10 17:32:04 +0000668 virtual DeclTy *ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Steve Naroff0c37b0c2007-10-02 22:39:18 +0000669 IdentifierInfo **IdentList,
670 unsigned NumElts);
Fariborz Jahanianea7a98d2007-10-05 21:01:53 +0000671
Fariborz Jahanian70e8f102007-10-11 00:55:41 +0000672 virtual void FindProtocolDeclaration(SourceLocation TypeLoc,
673 IdentifierInfo **ProtocolId,
674 unsigned NumProtocols,
675 llvm::SmallVector<DeclTy *, 8> &
676 Protocols);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +0000677
678 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
679 ObjCPropertyDecl *SuperProperty,
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +0000680 const char *Name);
Fariborz Jahanian7cf18862008-05-01 00:03:38 +0000681 void ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl);
Fariborz Jahanian0a070ff2008-04-24 19:58:34 +0000682
Fariborz Jahanian98a6c4f2008-05-02 19:17:30 +0000683 void MergeProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
684 DeclTy *MergeProtocols);
685
686 void MergeOneProtocolPropertiesIntoClass(ObjCInterfaceDecl *IDecl,
687 ObjCProtocolDecl *PDecl);
688
Steve Naroffcac26f42007-11-11 17:19:15 +0000689 virtual void ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
690 DeclTy **allMethods = 0, unsigned allNum = 0,
691 DeclTy **allProperties = 0, unsigned pNum = 0);
Fariborz Jahanian2a4dd312007-09-26 18:27:25 +0000692
Fariborz Jahanian0152a1a2008-04-14 23:36:35 +0000693 virtual DeclTy *ActOnProperty(Scope *S, SourceLocation AtLoc,
Fariborz Jahanian8d916862008-05-05 18:51:55 +0000694 FieldDeclarator &FD, ObjCDeclSpec &ODS,
Fariborz Jahanian09367d62008-05-06 18:09:04 +0000695 Selector GetterSel, Selector SetterSel,
Fariborz Jahanian8d916862008-05-05 18:51:55 +0000696 tok::ObjCKeywordKind MethodImplKind);
697
Fariborz Jahanianffe97a32008-04-18 00:19:30 +0000698 virtual DeclTy *ActOnPropertyImplDecl(SourceLocation AtLoc,
699 SourceLocation PropertyLoc,
700 bool ImplKind, DeclTy *ClassImplDecl,
701 IdentifierInfo *PropertyId,
702 IdentifierInfo *PropertyIvar);
703
Steve Naroff161a92b2007-10-26 20:53:56 +0000704 virtual DeclTy *ActOnMethodDeclaration(
705 SourceLocation BeginLoc, // location of the + or -.
706 SourceLocation EndLoc, // location of the ; or {.
Fariborz Jahanianb5605172007-11-09 19:52:12 +0000707 tok::TokenKind MethodType,
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000708 DeclTy *ClassDecl, ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
Fariborz Jahanian7a9c4742007-10-31 23:53:01 +0000709 Selector Sel,
Steve Narofff73590d2007-09-27 14:38:14 +0000710 // optional arguments. The number of types/arguments is obtained
711 // from the Sel.getNumArgs().
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000712 ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
Steve Naroffd8ea1ac2007-11-15 12:35:21 +0000713 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
714 bool isVariadic = false);
Steve Naroff077c83b2007-10-16 23:12:48 +0000715
Steve Narofff73590d2007-09-27 14:38:14 +0000716 // ActOnClassMessage - used for both unary and keyword messages.
717 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000718 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +0000719 virtual ExprResult ActOnClassMessage(
Fariborz Jahaniand98a7342007-11-12 20:13:27 +0000720 Scope *S,
Steve Naroff80175062007-09-28 22:22:11 +0000721 IdentifierInfo *receivingClassName, Selector Sel,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000722 SourceLocation lbrac, SourceLocation rbrac,
723 ExprTy **ArgExprs, unsigned NumArgs);
Steve Narofff73590d2007-09-27 14:38:14 +0000724
725 // ActOnInstanceMessage - used for both unary and keyword messages.
726 // ArgExprs is optional - if it is present, the number of expressions
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000727 // is obtained from NumArgs.
Steve Narofff73590d2007-09-27 14:38:14 +0000728 virtual ExprResult ActOnInstanceMessage(
Steve Naroff80175062007-09-28 22:22:11 +0000729 ExprTy *receiver, Selector Sel,
Steve Naroffe3ffc2f2007-11-15 13:05:42 +0000730 SourceLocation lbrac, SourceLocation rbrac,
731 ExprTy **ArgExprs, unsigned NumArgs);
Steve Naroff26c8ea52007-03-21 21:08:52 +0000732private:
Chris Lattnera65e1f32008-01-16 19:17:22 +0000733 /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit
734 /// cast. If there is already an implicit cast, merge into the existing one.
735 void ImpCastExprToType(Expr *&Expr, QualType Type);
736
Steve Naroff71b59a92007-06-04 22:22:31 +0000737 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Chris Lattner08464942007-12-28 05:29:59 +0000738 // functions and arrays to their respective pointers (C99 6.3.2.1).
739 Expr *UsualUnaryConversions(Expr *&expr);
Eli Friedman3e113402008-05-27 03:33:27 +0000740
741 // UsualUnaryConversionType - Same as UsualUnaryConversions, but works
742 // on types instead of expressions
743 QualType UsualUnaryConversionType(QualType Ty);
Steve Naroff31090012007-07-16 21:54:35 +0000744
745 // DefaultFunctionArrayConversion - converts functions and arrays
746 // to their respective pointers (C99 6.3.2.1).
747 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000748
Steve Naroff0b661582007-08-28 23:30:39 +0000749 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
750 // do not have a prototype. Integer promotions are performed on each
751 // argument, and arguments that have type float are promoted to double.
Chris Lattner08464942007-12-28 05:29:59 +0000752 void DefaultArgumentPromotion(Expr *&Expr);
Steve Naroff0b661582007-08-28 23:30:39 +0000753
Steve Naroff71b59a92007-06-04 22:22:31 +0000754 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
755 // operands and then handles various conversions that are common to binary
756 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
757 // routine returns the first non-arithmetic type found. The client is
758 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000759 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
760 bool isCompAssign = false);
Chris Lattner940cfeb2008-01-04 18:22:42 +0000761
762 /// AssignConvertType - All of the 'assignment' semantic checks return this
763 /// enum to indicate whether the assignment was allowed. These checks are
764 /// done for simple assignments, as well as initialization, return from
765 /// function, argument passing, etc. The query is phrased in terms of a
766 /// source and destination type.
Chris Lattner9bad62c2008-01-04 18:04:52 +0000767 enum AssignConvertType {
Chris Lattner940cfeb2008-01-04 18:22:42 +0000768 /// Compatible - the types are compatible according to the standard.
Steve Naroff17f76e02007-05-03 21:03:48 +0000769 Compatible,
Chris Lattner940cfeb2008-01-04 18:22:42 +0000770
771 /// PointerToInt - The assignment converts a pointer to an int, which we
772 /// accept as an extension.
773 PointerToInt,
774
775 /// IntToPointer - The assignment converts an int to a pointer, which we
776 /// accept as an extension.
777 IntToPointer,
778
779 /// FunctionVoidPointer - The assignment is between a function pointer and
780 /// void*, which the standard doesn't allow, but we accept as an extension.
Chris Lattner0a788432008-01-03 22:56:36 +0000781 FunctionVoidPointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +0000782
783 /// IncompatiblePointer - The assignment is between two pointers types that
784 /// are not compatible, but we accept them as an extension.
Steve Naroff1f4d7272007-05-11 04:00:31 +0000785 IncompatiblePointer,
Chris Lattner940cfeb2008-01-04 18:22:42 +0000786
787 /// CompatiblePointerDiscardsQualifiers - The assignment discards
788 /// c/v/r qualifiers, which we accept as an extension.
789 CompatiblePointerDiscardsQualifiers,
790
791 /// Incompatible - We reject this conversion outright, it is invalid to
792 /// represent it in the AST.
793 Incompatible
Steve Naroff17f76e02007-05-03 21:03:48 +0000794 };
Chris Lattner9bad62c2008-01-04 18:04:52 +0000795
796 /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the
797 /// assignment conversion type specified by ConvTy. This returns true if the
798 /// conversion was invalid or false if the conversion was accepted.
799 bool DiagnoseAssignmentResult(AssignConvertType ConvTy,
800 SourceLocation Loc,
801 QualType DstType, QualType SrcType,
802 Expr *SrcExpr, const char *Flavor);
803
804 /// CheckAssignmentConstraints - Perform type checking for assignment,
805 /// argument passing, variable initialization, and function return values.
806 /// This routine is only used by the following two methods. C99 6.5.16.
807 AssignConvertType CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000808
Steve Naroff83895f72007-09-16 03:34:24 +0000809 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff66356bd2007-09-16 14:56:35 +0000810 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000811 // this routine performs the default function/array converions.
Chris Lattner9bad62c2008-01-04 18:04:52 +0000812 AssignConvertType CheckSingleAssignmentConstraints(QualType lhs,
813 Expr *&rExpr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000814 // CheckCompoundAssignmentConstraints - Type check without performing any
815 // conversions. For compound assignments, the "Check...Operands" methods
816 // perform the necessary conversions.
Chris Lattner9bad62c2008-01-04 18:04:52 +0000817 AssignConvertType CheckCompoundAssignmentConstraints(QualType lhs,
818 QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000819
Steve Naroff98cf3e92007-06-06 18:38:38 +0000820 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
Chris Lattner9bad62c2008-01-04 18:04:52 +0000821 AssignConvertType CheckPointerTypesForAssignment(QualType lhsType,
822 QualType rhsType);
Steve Naroff9eb24652007-05-02 21:58:15 +0000823
Steve Naroff8eeeb132007-05-08 21:09:37 +0000824 /// the following "Check" methods will return a valid/converted QualType
825 /// or a null QualType (indicating an error diagnostic was issued).
826
Steve Naroff83895f72007-09-16 03:34:24 +0000827 /// type checking binary operators (subroutines of ActOnBinOp).
Chris Lattner5c11c412007-12-12 05:47:28 +0000828 inline QualType InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Steve Naroff7a5af782007-07-13 16:58:59 +0000829 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000830 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000831 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000832 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000833 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000834 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000835 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000836 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000837 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000838 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000839 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnerb620c342007-08-26 01:18:55 +0000840 inline QualType CheckCompareOperands( // C99 6.5.8/9
841 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000842 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000843 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000844 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +0000845 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +0000846 // CheckAssignmentOperands is used for both simple and compound assignment.
847 // For simple assignment, pass both expressions and a null converted type.
848 // For compound assignment, pass both expressions and the converted type.
849 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0c1c7ed2007-08-24 22:33:52 +0000850 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000851 inline QualType CheckCommaOperands( // C99 6.5.17
Steve Naroff7a5af782007-07-13 16:58:59 +0000852 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +0000853 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +0000854 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Steve Naroff95af0132007-03-30 23:47:58 +0000855
Steve Naroff83895f72007-09-16 03:34:24 +0000856 /// type checking unary operators (subroutines of ActOnUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +0000857 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Steve Naroff71ce2e02007-05-18 22:53:50 +0000858 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
859 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
860 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
861 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
862 bool isSizeof);
Chris Lattner74ed76b2007-08-24 21:41:10 +0000863 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Narofff8fd09e2007-07-27 22:15:19 +0000864
865 /// type checking primary expressions.
Nate Begemance4d7fc2008-04-18 23:10:10 +0000866 QualType CheckExtVectorComponent(QualType baseType, SourceLocation OpLoc,
Steve Narofff8fd09e2007-07-27 22:15:19 +0000867 IdentifierInfo &Comp, SourceLocation CmpLoc);
868
Steve Naroff2fea1392007-09-02 02:04:30 +0000869 /// type checking declaration initializers (C99 6.7.8)
Steve Narofff8ecff22008-05-01 22:18:59 +0000870 friend class InitListChecker;
Steve Naroff98f72032008-01-10 22:15:12 +0000871 bool CheckInitializerTypes(Expr *&simpleInit_or_initList, QualType &declType);
872 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
Steve Naroff98f72032008-01-10 22:15:12 +0000873 bool CheckForConstantInitializer(Expr *e, QualType t);
Eli Friedmand5a55bd2008-05-20 13:48:25 +0000874 bool CheckArithmeticConstantExpression(const Expr* e);
875 bool CheckAddressConstantExpression(const Expr* e);
876 bool CheckAddressConstantExpressionLValue(const Expr* e);
Steve Naroff91f78082007-12-10 22:44:33 +0000877
Steve Naroffaf2a0222008-01-22 00:55:40 +0000878 StringLiteral *IsStringLiteralInit(Expr *Init, QualType DeclType);
879 bool CheckStringLiteralInit(StringLiteral *strLiteral, QualType &DeclT);
880
Anders Carlsson24c59952007-11-27 07:16:40 +0000881 // CheckVectorCast - check type constraints for vectors.
882 // Since vectors are an extension, there are no C standard reference for this.
883 // We allow casting between vectors and integer datatypes of the same size.
Anders Carlssonde71adf2007-11-27 05:51:55 +0000884 // returns true if the cast is invalid
885 bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty);
886
Steve Naroff077c83b2007-10-16 23:12:48 +0000887 // returns true if there were any incompatible arguments.
888 bool CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
Ted Kremenek1b0ea822008-01-07 19:49:32 +0000889 ObjCMethodDecl *Method);
Steve Naroff077c83b2007-10-16 23:12:48 +0000890
Chris Lattnerfc1c44a2007-08-23 05:46:52 +0000891 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
892 /// the specified width and sign. If an overflow occurs, detect it and emit
893 /// the specified diagnostic.
894 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
895 unsigned NewWidth, bool NewSign,
896 SourceLocation Loc, unsigned DiagID);
897
Chris Lattner2a3569b2008-04-07 05:30:13 +0000898 bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
899 bool ForCompare);
900
901
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000902 void InitBuiltinVaListType();
Eli Friedman149614b2008-06-03 21:01:11 +0000903
904 // Helper method to turn variable array types into
905 // constant array types in certain situations which would otherwise
906 // be errors
907 QualType TryFixInvalidVariablyModifiedType(QualType T);
Anders Carlsson7e13ab82007-10-15 20:28:48 +0000908
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000909 //===--------------------------------------------------------------------===//
910 // Extra semantic analysis beyond the C type system
Chris Lattner08464942007-12-28 05:29:59 +0000911private:
Eli Friedmana1b4ed82008-05-14 19:38:39 +0000912 Action::ExprResult CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
Chris Lattner08464942007-12-28 05:29:59 +0000913 bool CheckBuiltinCFStringArgument(Expr* Arg);
914 bool SemaBuiltinVAStart(CallExpr *TheCall);
915 bool SemaBuiltinUnorderedCompare(CallExpr *TheCall);
Eli Friedmanf8353032008-05-20 08:23:37 +0000916 bool SemaBuiltinStackAddress(CallExpr *TheCall);
Eli Friedmana1b4ed82008-05-14 19:38:39 +0000917 Action::ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall);
Chris Lattner08464942007-12-28 05:29:59 +0000918 void CheckPrintfArguments(CallExpr *TheCall,
919 bool HasVAListArg, unsigned format_idx);
Ted Kremenekcff94fa2007-08-17 16:46:58 +0000920 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
921 SourceLocation ReturnLoc);
Ted Kremenek43fb8b02007-11-25 00:58:00 +0000922 void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000923};
924
Steve Narofff8ecff22008-05-01 22:18:59 +0000925class InitListChecker {
926 Sema *SemaRef;
927 bool hadError;
928
929 void CheckImplicitInitList(InitListExpr *ParentIList, QualType T,
930 unsigned &Index);
Steve Naroff125d73d2008-05-06 00:23:44 +0000931 void CheckExplicitInitList(InitListExpr *IList, QualType &T,
Steve Narofff8ecff22008-05-01 22:18:59 +0000932 unsigned &Index);
933
Eli Friedman23a9e312008-05-19 19:16:24 +0000934 void CheckListElementTypes(InitListExpr *IList, QualType &DeclType,
935 unsigned &Index);
936 void CheckSubElementType(InitListExpr *IList, QualType ElemType,
937 unsigned &Index);
Steve Narofff8ecff22008-05-01 22:18:59 +0000938 // FIXME: Does DeclType need to be a reference type?
939 void CheckScalarType(InitListExpr *IList, QualType &DeclType,
940 unsigned &Index);
941 void CheckVectorType(InitListExpr *IList, QualType DeclType, unsigned &Index);
942 void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
Eli Friedman23a9e312008-05-19 19:16:24 +0000943 unsigned &Index);
Steve Narofff8ecff22008-05-01 22:18:59 +0000944 void CheckArrayType(InitListExpr *IList, QualType &DeclType, unsigned &Index);
945
946 int numArrayElements(QualType DeclType);
947 int numStructUnionElements(QualType DeclType);
948public:
949 InitListChecker(Sema *S, InitListExpr *IL, QualType &T);
950 bool HadError() { return hadError; }
951};
952
Chris Lattner7cee11f2006-11-03 06:42:29 +0000953
954} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +0000955
956#endif