blob: a965f7f7257f593609a298679fe8fbf9b3f34921 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Sema class, which performs semantic analysis and
11// builds ASTs.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_AST_SEMA_H
16#define LLVM_CLANG_AST_SEMA_H
17
18#include "clang/Parse/Action.h"
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/SmallVector.h"
21#include <vector>
22#include <string>
23
Chris Lattner3429a812007-08-23 05:46:52 +000024namespace llvm {
25 class APSInt;
26}
27
Chris Lattner4b009652007-07-25 00:24:17 +000028namespace clang {
29 class ASTContext;
30 class Preprocessor;
31 class Decl;
Steve Naroffd21bc0d2007-09-13 18:10:37 +000032 class ScopedDecl;
Chris Lattner4b009652007-07-25 00:24:17 +000033 class Expr;
Steve Naroff9091f3f2007-09-02 15:34:30 +000034 class InitListExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000035 class VarDecl;
36 class ParmVarDecl;
37 class TypedefDecl;
38 class FunctionDecl;
39 class QualType;
Chris Lattner3496d522007-09-04 02:45:27 +000040 struct LangOptions;
41 struct DeclaratorChunk;
Chris Lattner4b009652007-07-25 00:24:17 +000042 class Token;
43 class IntegerLiteral;
44 class ArrayType;
45 class LabelStmt;
46 class SwitchStmt;
Steve Naroff1b8a46c2007-07-27 22:15:19 +000047 class OCUVectorType;
Steve Naroff82113e32007-07-29 16:33:31 +000048 class TypedefDecl;
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +000049 class ObjcInterfaceDecl;
Fariborz Jahaniandd243ef2007-09-29 17:04:06 +000050 class ObjcProtocolDecl;
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +000051 class ObjcImplementationDecl;
Fariborz Jahaniana91aa322007-10-02 16:38:50 +000052 class ObjcCategoryImplDecl;
53 class ObjcCategoryDecl;
Steve Naroff82113e32007-07-29 16:33:31 +000054
Chris Lattner4b009652007-07-25 00:24:17 +000055/// Sema - This implements semantic analysis and AST building for C.
56class Sema : public Action {
57 Preprocessor &PP;
58
59 ASTContext &Context;
60
61 /// CurFunctionDecl - If inside of a function body, this contains a pointer to
62 /// the function decl for the function being parsed.
63 FunctionDecl *CurFunctionDecl;
64
65 /// LastInGroupList - This vector is populated when there are multiple
66 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
67 /// all but the last decl will be entered into this. This is used by the
68 /// ASTStreamer.
69 std::vector<Decl*> &LastInGroupList;
70
71 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
72 /// it (which acts like the label decl in some ways). Forward referenced
73 /// labels have a LabelStmt created for them with a null location & SubStmt.
74 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
75
76 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroff82113e32007-07-29 16:33:31 +000077
78 /// OCUVectorDecls - This is a list all the OCU vector types. This allows
79 /// us to associate a raw vector type with one of the OCU type names.
80 /// This is only necessary for issuing pretty diagnostics.
81 llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls;
Chris Lattner2e64c072007-08-10 20:18:51 +000082
83 // Enum values used by KnownFunctionIDs (see below).
84 enum {
85 id_printf,
86 id_fprintf,
87 id_sprintf,
88 id_snprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +000089 id_asprintf,
Ted Kremenek2d7e9532007-08-10 21:13:51 +000090 id_vsnprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +000091 id_vasprintf,
92 id_vfprintf,
93 id_vsprintf,
94 id_vprintf,
95 id_num_known_functions
96 };
97
98 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
99 /// of known functions used by the semantic analysis to do various
100 /// kinds of checking (e.g. checking format string errors in printf calls).
101 /// This list is populated upon the creation of a Sema object.
102 IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
103
Chris Lattner4b009652007-07-25 00:24:17 +0000104public:
105 Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
106
107 const LangOptions &getLangOptions() const;
108
109 /// The primitive diagnostic helpers - always returns true, which simplifies
110 /// error handling (i.e. less code).
111 bool Diag(SourceLocation Loc, unsigned DiagID);
112 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
113 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
114 const std::string &Msg2);
115
116 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
117 bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
118 bool Diag(SourceLocation Loc, unsigned DiagID,
119 SourceRange R1, SourceRange R2);
120 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
121 SourceRange R1);
122 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
123 SourceRange R1, SourceRange R2);
124 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
125 const std::string &Msg2, SourceRange R1);
126 bool Diag(SourceLocation Loc, unsigned DiagID,
127 const std::string &Msg1, const std::string &Msg2,
128 SourceRange R1, SourceRange R2);
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000129
Chris Lattnerb26b7ad2007-08-31 04:53:24 +0000130 virtual void DeleteExpr(ExprTy *E);
131 virtual void DeleteStmt(StmtTy *S);
132
Chris Lattner4b009652007-07-25 00:24:17 +0000133 //===--------------------------------------------------------------------===//
134 // Type Analysis / Processing: SemaType.cpp.
135 //
136 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
137
Steve Naroff0acc9c92007-09-15 18:49:24 +0000138 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000139
Steve Naroff0acc9c92007-09-15 18:49:24 +0000140 virtual TypeResult ActOnParamDeclaratorType(Scope *S, Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000141private:
142 //===--------------------------------------------------------------------===//
143 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
144 //
145 virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
Steve Naroff0acc9c92007-09-15 18:49:24 +0000146 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
Steve Naroff6a0e2092007-09-12 14:07:44 +0000147 void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
Chris Lattner4b009652007-07-25 00:24:17 +0000148 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
149
150 virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
151 virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
152 virtual void PopScope(SourceLocation Loc, Scope *S);
153
154 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
155 /// no declarator (e.g. "struct foo;") is parsed.
156 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
157
Steve Naroff0acc9c92007-09-15 18:49:24 +0000158 virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
Chris Lattner4b009652007-07-25 00:24:17 +0000159 SourceLocation KWLoc, IdentifierInfo *Name,
160 SourceLocation NameLoc, AttributeList *Attr);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000161 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart,
Chris Lattner4b009652007-07-25 00:24:17 +0000162 Declarator &D, ExprTy *BitfieldWidth);
Steve Naroffffeaa552007-09-14 23:09:53 +0000163
164 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000165 virtual void ActOnFields(Scope* S,
166 SourceLocation RecLoc, DeclTy *TagDecl,
Steve Naroffffeaa552007-09-14 23:09:53 +0000167 DeclTy **Fields, unsigned NumFields,
168 tok::ObjCKeywordKind *visibility = 0);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000169 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000170 DeclTy *LastEnumConstant,
171 SourceLocation IdLoc, IdentifierInfo *Id,
172 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000173 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000174 DeclTy **Elements, unsigned NumElements);
175private:
Steve Naroff0acc9c92007-09-15 18:49:24 +0000176 /// Subroutines of ActOnDeclarator()...
Steve Naroff2591e1b2007-09-13 23:52:58 +0000177 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl);
Steve Naroffcb597472007-09-13 21:41:19 +0000178 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
179 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
180 VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
Chris Lattner4b009652007-07-25 00:24:17 +0000181 /// AddTopLevelDecl - called after the decl has been fully processed.
182 /// Allows for bookkeeping and post-processing of each declaration.
183 void AddTopLevelDecl(Decl *current, Decl *last);
184
185 /// More parsing and symbol table subroutines...
186 ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
187 Scope *FnBodyScope);
Steve Naroffd21bc0d2007-09-13 18:10:37 +0000188 ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
189 SourceLocation IdLoc, Scope *S);
Steve Narofffa465d12007-10-02 20:01:56 +0000190 ObjcInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *Id);
Fariborz Jahaniandd243ef2007-09-29 17:04:06 +0000191 ObjcProtocolDecl *getObjCProtocolDecl(Scope *S,
192 IdentifierInfo *Id, SourceLocation IdLoc);
Steve Naroffd21bc0d2007-09-13 18:10:37 +0000193 ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
Steve Narofff0c31dd2007-09-16 16:16:00 +0000194 ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Chris Lattner4b009652007-07-25 00:24:17 +0000195 Scope *S);
196 // Decl attributes - this routine is the top level dispatcher.
197 void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,
198 AttributeList *declarator_postfix);
199 void HandleDeclAttribute(Decl *New, AttributeList *rawAttr);
200
201 // HandleVectorTypeAttribute - this attribute is only applicable to
202 // integral and float scalars, although arrays, pointers, and function
203 // return values are allowed in conjunction with this construct. Aggregates
204 // with this attribute are invalid, even if they are of the same size as a
205 // corresponding scalar.
206 // The raw attribute should contain precisely 1 argument, the vector size
207 // for the variable, measured in bytes. If curType and rawAttr are well
208 // formed, this routine will return a new vector type.
209 QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
Steve Naroff82113e32007-07-29 16:33:31 +0000210 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Chris Lattner4b009652007-07-25 00:24:17 +0000211
Fariborz Jahanianf7cf3a62007-09-29 17:14:55 +0000212 /// CheckProtocolMethodDefs - This routine checks unimpletented methods
213 /// Declared in protocol, and those referenced by it.
214 void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
215 const llvm::DenseMap<void *, char>& InsMap,
216 const llvm::DenseMap<void *, char>& ClsMap);
217
218 /// ImplMethodsVsClassMethods - This is main routine to warn if any method
219 /// remains unimplemented in the @implementation class.
220 void ImplMethodsVsClassMethods(ObjcImplementationDecl* IMPDecl,
221 ObjcInterfaceDecl* IDecl);
222
Fariborz Jahaniana91aa322007-10-02 16:38:50 +0000223 /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
224 /// category interface is implemented in the category @implementation.
225 void ImplCategoryMethodsVsIntfMethods(ObjcCategoryImplDecl *CatImplDecl,
226 ObjcCategoryDecl *CatClassDecl);
227
Chris Lattner4b009652007-07-25 00:24:17 +0000228 //===--------------------------------------------------------------------===//
229 // Statement Parsing Callbacks: SemaStmt.cpp.
230public:
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000231 virtual StmtResult ActOnExprStmt(ExprTy *Expr);
Chris Lattner4b009652007-07-25 00:24:17 +0000232
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000233 virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
234 virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnerf2b07572007-08-31 21:49:55 +0000235 StmtTy **Elts, unsigned NumElts,
236 bool isStmtExpr);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000237 virtual StmtResult ActOnDeclStmt(DeclTy *Decl);
238 virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
Chris Lattner4b009652007-07-25 00:24:17 +0000239 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
240 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000241 virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000242 SourceLocation ColonLoc, StmtTy *SubStmt,
243 Scope *CurScope);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000244 virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Chris Lattner4b009652007-07-25 00:24:17 +0000245 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000246 virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Chris Lattner4b009652007-07-25 00:24:17 +0000247 StmtTy *ThenVal, SourceLocation ElseLoc,
248 StmtTy *ElseVal);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000249 virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
250 virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
Chris Lattner4b009652007-07-25 00:24:17 +0000251 ExprTy *Body);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000252 virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
Chris Lattner4b009652007-07-25 00:24:17 +0000253 StmtTy *Body);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000254 virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner4b009652007-07-25 00:24:17 +0000255 SourceLocation WhileLoc, ExprTy *Cond);
256
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000257 virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000258 SourceLocation LParenLoc,
259 StmtTy *First, ExprTy *Second, ExprTy *Third,
260 SourceLocation RParenLoc, StmtTy *Body);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000261 virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000262 SourceLocation LabelLoc,
263 IdentifierInfo *LabelII);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000264 virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000265 SourceLocation StarLoc,
266 ExprTy *DestExp);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000267 virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000268 Scope *CurScope);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000269 virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Chris Lattner4b009652007-07-25 00:24:17 +0000270
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000271 virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000272 ExprTy *RetValExp);
273
274 //===--------------------------------------------------------------------===//
275 // Expression Parsing Callbacks: SemaExpr.cpp.
276
277 // Primary Expressions.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000278 virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
Chris Lattner4b009652007-07-25 00:24:17 +0000279 IdentifierInfo &II,
280 bool HasTrailingLParen);
Steve Naroff87d58b42007-09-16 03:34:24 +0000281 virtual ExprResult ActOnPreDefinedExpr(SourceLocation Loc,
Chris Lattner4b009652007-07-25 00:24:17 +0000282 tok::TokenKind Kind);
Steve Naroff87d58b42007-09-16 03:34:24 +0000283 virtual ExprResult ActOnNumericConstant(const Token &);
284 virtual ExprResult ActOnCharacterConstant(const Token &);
285 virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
Chris Lattner4b009652007-07-25 00:24:17 +0000286 ExprTy *Val);
287
Steve Naroff87d58b42007-09-16 03:34:24 +0000288 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner4b009652007-07-25 00:24:17 +0000289 /// fragments (e.g. "foo" "bar" L"baz").
Steve Naroff87d58b42007-09-16 03:34:24 +0000290 virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
Chris Lattner4b009652007-07-25 00:24:17 +0000291
292 // Binary/Unary Operators. 'Tok' is the token for the operator.
Steve Naroff87d58b42007-09-16 03:34:24 +0000293 virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
Chris Lattner4b009652007-07-25 00:24:17 +0000294 ExprTy *Input);
295 virtual ExprResult
Steve Naroff87d58b42007-09-16 03:34:24 +0000296 ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
Chris Lattner4b009652007-07-25 00:24:17 +0000297 SourceLocation LParenLoc, TypeTy *Ty,
298 SourceLocation RParenLoc);
299
Steve Naroff87d58b42007-09-16 03:34:24 +0000300 virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000301 tok::TokenKind Kind, ExprTy *Input);
302
Steve Naroff87d58b42007-09-16 03:34:24 +0000303 virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000304 ExprTy *Idx, SourceLocation RLoc);
Steve Naroff87d58b42007-09-16 03:34:24 +0000305 virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000306 tok::TokenKind OpKind,
307 SourceLocation MemberLoc,
308 IdentifierInfo &Member);
309
Steve Naroff87d58b42007-09-16 03:34:24 +0000310 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner4b009652007-07-25 00:24:17 +0000311 /// This provides the location of the left/right parens and a list of comma
312 /// locations.
Steve Naroff87d58b42007-09-16 03:34:24 +0000313 virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000314 ExprTy **Args, unsigned NumArgs,
315 SourceLocation *CommaLocs,
316 SourceLocation RParenLoc);
317
Steve Naroff87d58b42007-09-16 03:34:24 +0000318 virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner4b009652007-07-25 00:24:17 +0000319 SourceLocation RParenLoc, ExprTy *Op);
320
Steve Naroff87d58b42007-09-16 03:34:24 +0000321 virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner4b009652007-07-25 00:24:17 +0000322 SourceLocation RParenLoc, ExprTy *Op);
323
Steve Naroff87d58b42007-09-16 03:34:24 +0000324 virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000325 ExprTy **InitList, unsigned NumInit,
326 SourceLocation RParenLoc);
327
Steve Naroff87d58b42007-09-16 03:34:24 +0000328 virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
Chris Lattner4b009652007-07-25 00:24:17 +0000329 ExprTy *LHS,ExprTy *RHS);
330
Steve Naroff87d58b42007-09-16 03:34:24 +0000331 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner4b009652007-07-25 00:24:17 +0000332 /// in the case of a the GNU conditional expr extension.
Steve Naroff87d58b42007-09-16 03:34:24 +0000333 virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000334 SourceLocation ColonLoc,
335 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
336
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000337 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
338 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000339 IdentifierInfo *LabelII);
340
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000341 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner4b009652007-07-25 00:24:17 +0000342 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000343
344 /// __builtin_offsetof(type, a.b[123][456].c)
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000345 virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000346 SourceLocation TypeLoc, TypeTy *Arg1,
347 OffsetOfComponent *CompPtr,
348 unsigned NumComponents,
349 SourceLocation RParenLoc);
350
Steve Naroff63bad2d2007-08-01 22:05:33 +0000351 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000352 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +0000353 TypeTy *arg1, TypeTy *arg2,
354 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +0000355
356 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000357 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff93c53012007-08-03 21:21:27 +0000358 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
359 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000360
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000361 /// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
362 virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
Chris Lattner4b009652007-07-25 00:24:17 +0000363 SourceLocation LAngleBracketLoc, TypeTy *Ty,
364 SourceLocation RAngleBracketLoc,
365 SourceLocation LParenLoc, ExprTy *E,
366 SourceLocation RParenLoc);
367
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000368 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
369 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000370 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +0000371
372 // ParseObjCStringLiteral - Parse Objective-C string literals.
373 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlsson8be1d402007-08-22 15:14:15 +0000374 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
375 SourceLocation LParenLoc,
376 TypeTy *Ty,
377 SourceLocation RParenLoc);
378
Steve Naroff81f1bba2007-09-06 21:24:23 +0000379 // Objective-C declarations.
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000380 virtual DeclTy *ObjcStartClassInterface(Scope* S,
381 SourceLocation AtInterafceLoc,
Steve Naroff81f1bba2007-09-06 21:24:23 +0000382 IdentifierInfo *ClassName, SourceLocation ClassLoc,
383 IdentifierInfo *SuperName, SourceLocation SuperLoc,
384 IdentifierInfo **ProtocolNames, unsigned NumProtocols,
385 AttributeList *AttrList);
386
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000387 virtual DeclTy *ObjcStartProtoInterface(Scope* S,
388 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000389 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
390 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
391
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000392 virtual DeclTy *ObjcStartCatInterface(Scope* S,
393 SourceLocation AtInterfaceLoc,
Fariborz Jahanianf25220e2007-09-18 20:26:58 +0000394 IdentifierInfo *ClassName, SourceLocation ClassLoc,
395 IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
396 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
397
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000398 virtual DeclTy *ObjcStartClassImplementation(Scope* S,
399 SourceLocation AtClassImplLoc,
400 IdentifierInfo *ClassName, SourceLocation ClassLoc,
401 IdentifierInfo *SuperClassname,
402 SourceLocation SuperClassLoc);
403
Fariborz Jahaniana91aa322007-10-02 16:38:50 +0000404 virtual DeclTy *ObjcStartCategoryImplementation(Scope* S,
405 SourceLocation AtCatImplLoc,
406 IdentifierInfo *ClassName,
407 SourceLocation ClassLoc,
408 IdentifierInfo *CatName,
409 SourceLocation CatLoc);
410
Steve Naroff81f1bba2007-09-06 21:24:23 +0000411 virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
412 IdentifierInfo **IdentList,
413 unsigned NumElts);
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000414
415 virtual DeclTy *ObjcForwardProtocolDeclaration(Scope *S,
416 SourceLocation AtProtocolLoc,
417 IdentifierInfo **IdentList,
418 unsigned NumElts);
Steve Naroff81f1bba2007-09-06 21:24:23 +0000419
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000420 virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
Steve Naroff75494892007-09-11 21:17:26 +0000421 DeclTy **allMethods, unsigned allNum);
Fariborz Jahaniand34caf92007-09-26 18:27:25 +0000422
423 virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl,
424 DeclTy **Fields, unsigned NumFields);
425
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000426 virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
Steve Naroff6cb1d362007-09-28 22:22:11 +0000427 tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000428 // optional arguments. The number of types/arguments is obtained
429 // from the Sel.getNumArgs().
430 TypeTy **ArgTypes, IdentifierInfo **ArgNames,
431 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind);
Steve Naroffd3f5ee42007-09-17 21:01:15 +0000432
Steve Naroff4ed9d662007-09-27 14:38:14 +0000433 // ActOnClassMessage - used for both unary and keyword messages.
434 // ArgExprs is optional - if it is present, the number of expressions
435 // is obtained from Sel.getNumArgs().
436 virtual ExprResult ActOnClassMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +0000437 IdentifierInfo *receivingClassName, Selector Sel,
Steve Narofffa465d12007-10-02 20:01:56 +0000438 SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
Steve Naroff4ed9d662007-09-27 14:38:14 +0000439
440 // ActOnInstanceMessage - used for both unary and keyword messages.
441 // ArgExprs is optional - if it is present, the number of expressions
442 // is obtained from Sel.getNumArgs().
443 virtual ExprResult ActOnInstanceMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +0000444 ExprTy *receiver, Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000445 SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
Chris Lattner4b009652007-07-25 00:24:17 +0000446private:
447 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
448 // functions and arrays to their respective pointers (C99 6.3.2.1).
449 void UsualUnaryConversions(Expr *&expr);
450
451 // DefaultFunctionArrayConversion - converts functions and arrays
452 // to their respective pointers (C99 6.3.2.1).
453 void DefaultFunctionArrayConversion(Expr *&expr);
454
Steve Naroffdb65e052007-08-28 23:30:39 +0000455 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
456 // do not have a prototype. Integer promotions are performed on each
457 // argument, and arguments that have type float are promoted to double.
458 void DefaultArgumentPromotion(Expr *&expr);
459
Chris Lattner4b009652007-07-25 00:24:17 +0000460 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
461 // operands and then handles various conversions that are common to binary
462 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
463 // routine returns the first non-arithmetic type found. The client is
464 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +0000465 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
466 bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000467 enum AssignmentCheckResult {
468 Compatible,
469 Incompatible,
470 PointerFromInt,
471 IntFromPointer,
472 IncompatiblePointer,
473 CompatiblePointerDiscardsQualifiers
474 };
475 // CheckAssignmentConstraints - Perform type checking for assignment,
476 // argument passing, variable initialization, and function return values.
477 // This routine is only used by the following two methods. C99 6.5.16.
478 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
479
Steve Naroff87d58b42007-09-16 03:34:24 +0000480 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000481 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Chris Lattner4b009652007-07-25 00:24:17 +0000482 // this routine performs the default function/array converions.
483 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
484 Expr *&rExpr);
485 // CheckCompoundAssignmentConstraints - Type check without performing any
486 // conversions. For compound assignments, the "Check...Operands" methods
487 // perform the necessary conversions.
488 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
489 QualType rhs);
490
491 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
492 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
493 QualType rhsType);
494
495 /// the following "Check" methods will return a valid/converted QualType
496 /// or a null QualType (indicating an error diagnostic was issued).
497
Steve Naroff87d58b42007-09-16 03:34:24 +0000498 /// type checking binary operators (subroutines of ActOnBinOp).
Chris Lattner4b009652007-07-25 00:24:17 +0000499 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
500 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
501 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000502 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000503 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000504 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000505 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000506 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000507 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000508 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000509 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +0000510 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +0000511 inline QualType CheckCompareOperands( // C99 6.5.8/9
512 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +0000513 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff8f708362007-08-24 19:07:16 +0000514 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000515 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
516 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
517 // CheckAssignmentOperands is used for both simple and compound assignment.
518 // For simple assignment, pass both expressions and a null converted type.
519 // For compound assignment, pass both expressions and the converted type.
520 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +0000521 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +0000522 inline QualType CheckCommaOperands( // C99 6.5.17
523 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
524 inline QualType CheckConditionalOperands( // C99 6.5.15
525 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
526
Steve Naroff87d58b42007-09-16 03:34:24 +0000527 /// type checking unary operators (subroutines of ActOnUnaryOp).
Chris Lattner4b009652007-07-25 00:24:17 +0000528 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
529 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
530 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
531 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
532 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
533 bool isSizeof);
Chris Lattner5110ad52007-08-24 21:41:10 +0000534 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroff1b8a46c2007-07-27 22:15:19 +0000535
536 /// type checking primary expressions.
537 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
538 IdentifierInfo &Comp, SourceLocation CmpLoc);
539
Steve Naroffe14e5542007-09-02 02:04:30 +0000540 /// type checking declaration initializers (C99 6.7.8)
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000541 bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType,
Steve Naroff1c9de712007-09-03 01:24:23 +0000542 bool isStatic);
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000543 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
544 bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
545 bool isStatic, QualType ElementType);
Steve Naroff509d0b52007-09-04 02:20:04 +0000546 void CheckVariableInitList(QualType DeclType, InitListExpr *IList,
547 QualType ElementType, bool isStatic,
548 int &nInitializers, bool &hadError);
549 void CheckConstantInitList(QualType DeclType, InitListExpr *IList,
550 QualType ElementType, bool isStatic,
551 int &nInitializers, bool &hadError);
552
Chris Lattner3429a812007-08-23 05:46:52 +0000553 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
554 /// the specified width and sign. If an overflow occurs, detect it and emit
555 /// the specified diagnostic.
556 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
557 unsigned NewWidth, bool NewSign,
558 SourceLocation Loc, unsigned DiagID);
559
Chris Lattner2e64c072007-08-10 20:18:51 +0000560 //===--------------------------------------------------------------------===//
561 // Extra semantic analysis beyond the C type system
562 private:
563
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000564 bool CheckFunctionCall(Expr *Fn,
Ted Kremenek081ed872007-08-14 17:39:48 +0000565 SourceLocation LParenLoc, SourceLocation RParenLoc,
566 FunctionDecl *FDecl,
Chris Lattner2e64c072007-08-10 20:18:51 +0000567 Expr** Args, unsigned NumArgsInCall);
568
Ted Kremenek081ed872007-08-14 17:39:48 +0000569 void CheckPrintfArguments(Expr *Fn,
570 SourceLocation LParenLoc, SourceLocation RParenLoc,
571 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek30596542007-08-10 21:21:05 +0000572 unsigned format_idx, Expr** Args,
573 unsigned NumArgsInCall);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000574
575 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
576 SourceLocation ReturnLoc);
577
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000578
579 bool CheckBuiltinCFStringArgument(Expr* Arg);
Chris Lattner4b009652007-07-25 00:24:17 +0000580};
581
582
583} // end namespace clang
584
585#endif