blob: 7eae1822d2eaf0764ce59be4720017e461233148 [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//
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//
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
18#include "clang/Parse/Action.h"
Chris Lattnere2473062007-05-28 06:28:18 +000019#include "llvm/ADT/DenseMap.h"
Anders Carlsson51873c22007-07-22 07:07:56 +000020#include "llvm/ADT/SmallVector.h"
Chris Lattner7cee11f2006-11-03 06:42:29 +000021#include <vector>
Chris Lattnereaafe1222006-11-10 05:17:58 +000022#include <string>
Chris Lattner7cee11f2006-11-03 06:42:29 +000023
Chris Lattnerfc1c44a2007-08-23 05:46:52 +000024namespace llvm {
25 class APSInt;
26}
27
Chris Lattner7cee11f2006-11-03 06:42:29 +000028namespace clang {
Chris Lattnercb6a3822006-11-10 06:20:45 +000029 class ASTContext;
Chris Lattner7cee11f2006-11-03 06:42:29 +000030 class Preprocessor;
31 class Decl;
Steve Naroff78403362007-04-02 22:55:05 +000032 class Expr;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000033 class VarDecl;
Chris Lattner53621a52007-06-13 20:44:40 +000034 class ParmVarDecl;
Chris Lattner01564d92007-01-27 19:27:06 +000035 class TypedefDecl;
36 class FunctionDecl;
Steve Naroffe5aa9be2007-04-05 22:36:20 +000037 class QualType;
Chris Lattnerac18be92006-11-20 06:49:47 +000038 class LangOptions;
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +000039 class DeclaratorChunk;
Chris Lattner146762e2007-07-20 16:59:19 +000040 class Token;
Steve Naroff35d85152007-05-07 00:24:15 +000041 class IntegerLiteral;
Steve Naroff8eeeb132007-05-08 21:09:37 +000042 class ArrayType;
Chris Lattnere2473062007-05-28 06:28:18 +000043 class LabelStmt;
Anders Carlsson51873c22007-07-22 07:07:56 +000044 class SwitchStmt;
Steve Narofff8fd09e2007-07-27 22:15:19 +000045 class OCUVectorType;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000046 class TypedefDecl;
47
Chris Lattnercc67ec12006-11-09 06:54:47 +000048/// Sema - This implements semantic analysis and AST building for C.
49class Sema : public Action {
Steve Naroff38d31b42007-02-28 01:22:02 +000050 Preprocessor &PP;
51
Chris Lattnercb6a3822006-11-10 06:20:45 +000052 ASTContext &Context;
Chris Lattner7cee11f2006-11-03 06:42:29 +000053
Chris Lattner229ce602006-11-21 01:21:07 +000054 /// CurFunctionDecl - If inside of a function body, this contains a pointer to
55 /// the function decl for the function being parsed.
56 FunctionDecl *CurFunctionDecl;
57
Chris Lattner7cee11f2006-11-03 06:42:29 +000058 /// LastInGroupList - This vector is populated when there are multiple
59 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
60 /// all but the last decl will be entered into this. This is used by the
61 /// ASTStreamer.
62 std::vector<Decl*> &LastInGroupList;
Chris Lattnere2473062007-05-28 06:28:18 +000063
64 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
65 /// it (which acts like the label decl in some ways). Forward referenced
66 /// labels have a LabelStmt created for them with a null location & SubStmt.
Chris Lattner23b7eb62007-06-15 23:05:46 +000067 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
Anders Carlsson51873c22007-07-22 07:07:56 +000068
69 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffddf5a1d2007-07-29 16:33:31 +000070
71 /// OCUVectorDecls - This is a list all the OCU vector types. This allows
72 /// us to associate a raw vector type with one of the OCU type names.
73 /// This is only necessary for issuing pretty diagnostics.
74 llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls;
Chris Lattnerb87b1b32007-08-10 20:18:51 +000075
76 // Enum values used by KnownFunctionIDs (see below).
77 enum {
78 id_printf,
79 id_fprintf,
80 id_sprintf,
81 id_snprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +000082 id_asprintf,
Ted Kremenekcfc94192007-08-10 21:13:51 +000083 id_vsnprintf,
Chris Lattnerb87b1b32007-08-10 20:18:51 +000084 id_vasprintf,
85 id_vfprintf,
86 id_vsprintf,
87 id_vprintf,
88 id_num_known_functions
89 };
90
91 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
92 /// of known functions used by the semantic analysis to do various
93 /// kinds of checking (e.g. checking format string errors in printf calls).
94 /// This list is populated upon the creation of a Sema object.
95 IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
96
Chris Lattner7cee11f2006-11-03 06:42:29 +000097public:
Steve Naroff2c055d22007-02-28 19:32:13 +000098 Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
Chris Lattner7cee11f2006-11-03 06:42:29 +000099
Chris Lattnerac18be92006-11-20 06:49:47 +0000100 const LangOptions &getLangOptions() const;
101
Steve Naroff71ce2e02007-05-18 22:53:50 +0000102 /// The primitive diagnostic helpers - always returns true, which simplifies
103 /// error handling (i.e. less code).
Chris Lattnerd6647d32007-05-16 17:56:50 +0000104 bool Diag(SourceLocation Loc, unsigned DiagID);
105 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
106 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
107 const std::string &Msg2);
Steve Naroff71ce2e02007-05-18 22:53:50 +0000108
109 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
110 bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
111 bool Diag(SourceLocation Loc, unsigned DiagID,
112 SourceRange R1, SourceRange R2);
113 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
114 SourceRange R1);
115 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
116 SourceRange R1, SourceRange R2);
117 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
118 const std::string &Msg2, SourceRange R1);
119 bool Diag(SourceLocation Loc, unsigned DiagID,
120 const std::string &Msg1, const std::string &Msg2,
121 SourceRange R1, SourceRange R2);
122
Chris Lattner7cee11f2006-11-03 06:42:29 +0000123 //===--------------------------------------------------------------------===//
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000124 // Type Analysis / Processing: SemaType.cpp.
125 //
Steve Naroffe5aa9be2007-04-05 22:36:20 +0000126 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000127
Chris Lattner33e8a552006-11-19 01:48:02 +0000128 virtual TypeResult ParseTypeName(Scope *S, Declarator &D);
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000129
Chris Lattner216d8652006-12-02 06:47:41 +0000130 virtual TypeResult ParseParamDeclaratorType(Scope *S, Declarator &D);
Steve Naroff26c8ea52007-03-21 21:08:52 +0000131private:
Chris Lattnerf84a79c2006-11-11 22:59:23 +0000132 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000133 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000134 //
Chris Lattner2ebe4bb2006-11-20 01:29:42 +0000135 virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
Chris Lattner7cee11f2006-11-03 06:42:29 +0000136 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
137 DeclTy *LastInGroup);
Chris Lattner776fac82007-06-09 00:53:06 +0000138 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
139
Chris Lattnerc5cdf4d2007-01-21 07:42:07 +0000140 virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
Chris Lattner229ce602006-11-21 01:21:07 +0000141 virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000142 virtual void PopScope(SourceLocation Loc, Scope *S);
Chris Lattner01564d92007-01-27 19:27:06 +0000143
Chris Lattner200bdc32006-11-19 02:43:37 +0000144 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
145 /// no declarator (e.g. "struct foo;") is parsed.
146 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
147
Chris Lattner7b9ace62007-01-23 20:11:08 +0000148 virtual DeclTy *ParseTag(Scope *S, unsigned TagType, TagKind TK,
Chris Lattnerf34c4da2007-01-23 04:08:05 +0000149 SourceLocation KWLoc, IdentifierInfo *Name,
Steve Naroffb3096442007-06-09 03:47:53 +0000150 SourceLocation NameLoc, AttributeList *Attr);
Chris Lattner1300fb92007-01-23 23:42:53 +0000151 virtual DeclTy *ParseField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart,
152 Declarator &D, ExprTy *BitfieldWidth);
153 virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl,
154 DeclTy **Fields, unsigned NumFields);
Chris Lattnerc1915e22007-01-25 07:29:02 +0000155 virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4ef40012007-06-11 01:28:17 +0000156 DeclTy *LastEnumConstant,
Chris Lattnerc1915e22007-01-25 07:29:02 +0000157 SourceLocation IdLoc, IdentifierInfo *Id,
158 SourceLocation EqualLoc, ExprTy *Val);
159 virtual void ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
160 DeclTy **Elements, unsigned NumElements);
Steve Naroff3273c222007-03-14 21:52:03 +0000161private:
162 /// Subroutines of ParseDeclarator()...
Chris Lattner776fac82007-06-09 00:53:06 +0000163 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
Steve Naroff3273c222007-03-14 21:52:03 +0000164 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
165 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old);
166 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
Steve Naroff26c8ea52007-03-21 21:08:52 +0000167 /// AddTopLevelDecl - called after the decl has been fully processed.
168 /// Allows for bookkeeping and post-processing of each declaration.
169 void AddTopLevelDecl(Decl *current, Decl *last);
Steve Naroff6fbf0dc2007-03-16 00:33:25 +0000170
Steve Naroff3273c222007-03-14 21:52:03 +0000171 /// More parsing and symbol table subroutines...
Chris Lattner53621a52007-06-13 20:44:40 +0000172 ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
173 Scope *FnBodyScope);
Steve Naroff3273c222007-03-14 21:52:03 +0000174 Decl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc,
175 Scope *S);
176 Decl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
177 Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
178 Scope *S);
Steve Naroffa8fd9732007-06-11 00:35:03 +0000179 // Decl attributes - this routine is the top level dispatcher.
180 void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,
181 AttributeList *declarator_postfix);
182 void HandleDeclAttribute(Decl *New, AttributeList *rawAttr);
183
184 // HandleVectorTypeAttribute - this attribute is only applicable to
185 // integral and float scalars, although arrays, pointers, and function
186 // return values are allowed in conjunction with this construct. Aggregates
187 // with this attribute are invalid, even if they are of the same size as a
188 // corresponding scalar.
189 // The raw attribute should contain precisely 1 argument, the vector size
190 // for the variable, measured in bytes. If curType and rawAttr are well
191 // formed, this routine will return a new vector type.
Steve Naroff4ae0ac62007-07-06 23:09:18 +0000192 QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
Steve Naroffddf5a1d2007-07-29 16:33:31 +0000193 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Chris Lattner1300fb92007-01-23 23:42:53 +0000194
Chris Lattner7cee11f2006-11-03 06:42:29 +0000195 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000196 // Statement Parsing Callbacks: SemaStmt.cpp.
Steve Naroff3273c222007-03-14 21:52:03 +0000197public:
Chris Lattner1ec5f562007-06-27 05:38:08 +0000198 virtual StmtResult ParseExprStmt(ExprTy *Expr);
199
Chris Lattner0f203a72007-05-28 01:45:28 +0000200 virtual StmtResult ParseNullStmt(SourceLocation SemiLoc);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000201 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
202 StmtTy **Elts, unsigned NumElts);
Steve Naroff2a8ad182007-05-29 22:59:26 +0000203 virtual StmtResult ParseDeclStmt(DeclTy *Decl);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000204 virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
205 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
206 SourceLocation ColonLoc, StmtTy *SubStmt);
207 virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
Chris Lattner46eeb222007-07-18 02:28:47 +0000208 SourceLocation ColonLoc, StmtTy *SubStmt,
209 Scope *CurScope);
Chris Lattner6c0ff132006-11-05 00:19:50 +0000210 virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
211 SourceLocation ColonLoc, StmtTy *SubStmt);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000212 virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
213 StmtTy *ThenVal, SourceLocation ElseLoc,
214 StmtTy *ElseVal);
Anders Carlsson51873c22007-07-22 07:07:56 +0000215 virtual StmtResult StartSwitchStmt(ExprTy *Cond);
216 virtual StmtResult FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
217 ExprTy *Body);
Chris Lattner85ed8732006-11-04 20:40:44 +0000218 virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
219 StmtTy *Body);
220 virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,
221 SourceLocation WhileLoc, ExprTy *Cond);
222
Chris Lattner71e23ce2006-11-04 20:18:38 +0000223 virtual StmtResult ParseForStmt(SourceLocation ForLoc,
224 SourceLocation LParenLoc,
225 StmtTy *First, ExprTy *Second, ExprTy *Third,
226 SourceLocation RParenLoc, StmtTy *Body);
Chris Lattner16976d32006-11-05 01:46:01 +0000227 virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc,
228 SourceLocation LabelLoc,
229 IdentifierInfo *LabelII);
230 virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
231 SourceLocation StarLoc,
232 ExprTy *DestExp);
Chris Lattnereaafe1222006-11-10 05:17:58 +0000233 virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
234 Scope *CurScope);
235 virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Chris Lattner71e23ce2006-11-04 20:18:38 +0000236
Chris Lattner7cee11f2006-11-03 06:42:29 +0000237 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
238 ExprTy *RetValExp);
239
240 //===--------------------------------------------------------------------===//
Chris Lattnere168f762006-11-10 05:29:30 +0000241 // Expression Parsing Callbacks: SemaExpr.cpp.
Chris Lattner7cee11f2006-11-03 06:42:29 +0000242
243 // Primary Expressions.
Chris Lattnerac18be92006-11-20 06:49:47 +0000244 virtual ExprResult ParseIdentifierExpr(Scope *S, SourceLocation Loc,
245 IdentifierInfo &II,
246 bool HasTrailingLParen);
Anders Carlsson625bfc82007-07-21 05:21:51 +0000247 virtual ExprResult ParsePreDefinedExpr(SourceLocation Loc,
Chris Lattner7cee11f2006-11-03 06:42:29 +0000248 tok::TokenKind Kind);
Chris Lattner146762e2007-07-20 16:59:19 +0000249 virtual ExprResult ParseNumericConstant(const Token &);
250 virtual ExprResult ParseCharacterConstant(const Token &);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000251 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
252 ExprTy *Val);
Chris Lattner697e5d62006-11-09 06:32:27 +0000253
Steve Naroffdf7855b2007-02-21 23:46:25 +0000254 /// ParseStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner697e5d62006-11-09 06:32:27 +0000255 /// fragments (e.g. "foo" "bar" L"baz").
Chris Lattner146762e2007-07-20 16:59:19 +0000256 virtual ExprResult ParseStringLiteral(const Token *Toks, unsigned NumToks);
Chris Lattner697e5d62006-11-09 06:32:27 +0000257
Chris Lattner7cee11f2006-11-03 06:42:29 +0000258 // Binary/Unary Operators. 'Tok' is the token for the operator.
259 virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
260 ExprTy *Input);
261 virtual ExprResult
262 ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
263 SourceLocation LParenLoc, TypeTy *Ty,
264 SourceLocation RParenLoc);
265
266 virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
267 tok::TokenKind Kind, ExprTy *Input);
268
269 virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
270 ExprTy *Idx, SourceLocation RLoc);
271 virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
272 tok::TokenKind OpKind,
273 SourceLocation MemberLoc,
274 IdentifierInfo &Member);
275
276 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
277 /// This provides the location of the left/right parens and a list of comma
278 /// locations.
279 virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
280 ExprTy **Args, unsigned NumArgs,
281 SourceLocation *CommaLocs,
282 SourceLocation RParenLoc);
283
284 virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
285 SourceLocation RParenLoc, ExprTy *Op);
Steve Narofffbd09832007-07-19 01:06:55 +0000286
287 virtual ExprResult ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
288 SourceLocation RParenLoc, ExprTy *Op);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000289
Steve Narofffbd09832007-07-19 01:06:55 +0000290 virtual ExprResult ParseInitList(SourceLocation LParenLoc,
291 ExprTy **InitList, unsigned NumInit,
292 SourceLocation RParenLoc);
293
Chris Lattner7cee11f2006-11-03 06:42:29 +0000294 virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
295 ExprTy *LHS,ExprTy *RHS);
296
297 /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
298 /// in the case of a the GNU conditional expr extension.
299 virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
300 SourceLocation ColonLoc,
301 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
Chris Lattner29375652006-12-04 18:06:35 +0000302
Chris Lattnereefa10e2007-05-28 06:56:27 +0000303 /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo".
304 virtual ExprResult ParseAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
305 IdentifierInfo *LabelII);
306
Chris Lattner366727f2007-07-24 16:58:17 +0000307 virtual ExprResult ParseStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
308 SourceLocation RPLoc); // "({..})"
Steve Naroff78864672007-08-01 22:05:33 +0000309
310 // __builtin_types_compatible_p(type1, type2)
Steve Naroff788d8642007-08-01 23:45:51 +0000311 virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff78864672007-08-01 22:05:33 +0000312 TypeTy *arg1, TypeTy *arg2,
313 SourceLocation RPLoc);
Steve Naroff9efdabc2007-08-03 21:21:27 +0000314
315 // __builtin_choose_expr(constExpr, expr1, expr2)
316 virtual ExprResult ParseChooseExpr(SourceLocation BuiltinLoc,
317 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
318 SourceLocation RPLoc);
Chris Lattner366727f2007-07-24 16:58:17 +0000319
Chris Lattner29375652006-12-04 18:06:35 +0000320 /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
321 virtual ExprResult ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
322 SourceLocation LAngleBracketLoc, TypeTy *Ty,
323 SourceLocation RAngleBracketLoc,
324 SourceLocation LParenLoc, ExprTy *E,
325 SourceLocation RParenLoc);
Bill Wendling4073ed52007-02-13 01:51:42 +0000326
327 /// ParseCXXBoolLiteral - Parse {true,false} literals.
328 virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
Bill Wendlingbf313b02007-02-13 20:09:46 +0000329 tok::TokenKind Kind);
Anders Carlsson76f4a902007-08-21 17:43:55 +0000330
331 // ParseObjCStringLiteral - Parse Objective-C string literals.
332 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlssonc5a81eb2007-08-22 15:14:15 +0000333 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
334 SourceLocation LParenLoc,
335 TypeTy *Ty,
336 SourceLocation RParenLoc);
337
Steve Naroff26c8ea52007-03-21 21:08:52 +0000338private:
Steve Naroff71b59a92007-06-04 22:22:31 +0000339 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Steve Naroff31090012007-07-16 21:54:35 +0000340 // functions and arrays to their respective pointers (C99 6.3.2.1).
341 void UsualUnaryConversions(Expr *&expr);
342
343 // DefaultFunctionArrayConversion - converts functions and arrays
344 // to their respective pointers (C99 6.3.2.1).
345 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000346
Steve Naroff71b59a92007-06-04 22:22:31 +0000347 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
348 // operands and then handles various conversions that are common to binary
349 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
350 // routine returns the first non-arithmetic type found. The client is
351 // responsible for emitting appropriate error diagnostics.
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000352 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
353 bool isCompAssign = false);
Steve Naroff98cf3e92007-06-06 18:38:38 +0000354 enum AssignmentCheckResult {
Steve Naroff17f76e02007-05-03 21:03:48 +0000355 Compatible,
356 Incompatible,
357 PointerFromInt,
358 IntFromPointer,
Steve Naroff1f4d7272007-05-11 04:00:31 +0000359 IncompatiblePointer,
360 CompatiblePointerDiscardsQualifiers
Steve Naroff17f76e02007-05-03 21:03:48 +0000361 };
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000362 // CheckAssignmentConstraints - Perform type checking for assignment,
363 // argument passing, variable initialization, and function return values.
364 // This routine is only used by the following two methods. C99 6.5.16.
Steve Naroff98cf3e92007-06-06 18:38:38 +0000365 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroffb8ea4fb2007-07-13 23:32:42 +0000366
367 // CheckSingleAssignmentConstraints - Currently used by ParseCallExpr,
368 // CheckAssignmentOperands, and ParseReturnStmt. Prior to type checking,
369 // this routine performs the default function/array converions.
370 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
371 Expr *&rExpr);
372 // CheckCompoundAssignmentConstraints - Type check without performing any
373 // conversions. For compound assignments, the "Check...Operands" methods
374 // perform the necessary conversions.
375 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
376 QualType rhs);
377
Steve Naroff98cf3e92007-06-06 18:38:38 +0000378 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
379 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
380 QualType rhsType);
Steve Naroff9eb24652007-05-02 21:58:15 +0000381
Steve Naroff8eeeb132007-05-08 21:09:37 +0000382 /// the following "Check" methods will return a valid/converted QualType
383 /// or a null QualType (indicating an error diagnostic was issued).
384
Steve Naroff47500512007-04-19 23:00:49 +0000385 /// type checking binary operators (subroutines of ParseBinOp).
Steve Naroff7a5af782007-07-13 16:58:59 +0000386 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
387 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000388 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000389 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000390 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000391 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000392 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000393 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000394 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000395 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000396 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000397 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000398 inline QualType CheckRelationalOperands( // C99 6.5.8
Steve Naroff7a5af782007-07-13 16:58:59 +0000399 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000400 inline QualType CheckEqualityOperands( // C99 6.5.9
Steve Naroff7a5af782007-07-13 16:58:59 +0000401 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000402 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroffbe4c4d12007-08-24 19:07:16 +0000403 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000404 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff7a5af782007-07-13 16:58:59 +0000405 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Naroff35d85152007-05-07 00:24:15 +0000406 // CheckAssignmentOperands is used for both simple and compound assignment.
407 // For simple assignment, pass both expressions and a null converted type.
408 // For compound assignment, pass both expressions and the converted type.
409 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
410 Expr *lex, Expr *rex, SourceLocation OpLoc, QualType convertedType);
Steve Naroff218bc2b2007-05-04 21:54:46 +0000411 inline QualType CheckCommaOperands( // C99 6.5.17
Steve Naroff7a5af782007-07-13 16:58:59 +0000412 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Steve Narofff8a28c52007-05-15 20:29:32 +0000413 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff7a5af782007-07-13 16:58:59 +0000414 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Steve Naroff95af0132007-03-30 23:47:58 +0000415
Steve Naroff47500512007-04-19 23:00:49 +0000416 /// type checking unary operators (subroutines of ParseUnaryOp).
Steve Naroff9358c712007-05-27 23:58:33 +0000417 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
Steve Naroff71ce2e02007-05-18 22:53:50 +0000418 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
419 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
420 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
421 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
422 bool isSizeof);
Chris Lattner74ed76b2007-08-24 21:41:10 +0000423 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Narofff8fd09e2007-07-27 22:15:19 +0000424
425 /// type checking primary expressions.
426 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
427 IdentifierInfo &Comp, SourceLocation CmpLoc);
428
Chris Lattner6046e002007-06-05 06:39:23 +0000429 /// C99: 6.7.5p3: Used by ParseDeclarator/ParseField to make sure we have
430 /// a constant expression of type int with a value greater than zero. If the
431 /// array has an incomplete type or a valid constant size, return false,
432 /// otherwise emit a diagnostic and return true.
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000433 bool VerifyConstantArrayType(const ArrayType *ary, SourceLocation loc);
434
Chris Lattnerfc1c44a2007-08-23 05:46:52 +0000435 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
436 /// the specified width and sign. If an overflow occurs, detect it and emit
437 /// the specified diagnostic.
438 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
439 unsigned NewWidth, bool NewSign,
440 SourceLocation Loc, unsigned DiagID);
441
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000442 //===--------------------------------------------------------------------===//
443 // Extra semantic analysis beyond the C type system
444 private:
445
Anders Carlsson98f07902007-08-17 05:31:46 +0000446 bool CheckFunctionCall(Expr *Fn,
Ted Kremeneke68f1aa2007-08-14 17:39:48 +0000447 SourceLocation LParenLoc, SourceLocation RParenLoc,
448 FunctionDecl *FDecl,
Chris Lattnerb87b1b32007-08-10 20:18:51 +0000449 Expr** Args, unsigned NumArgsInCall);
450
Ted Kremeneke68f1aa2007-08-14 17:39:48 +0000451 void CheckPrintfArguments(Expr *Fn,
452 SourceLocation LParenLoc, SourceLocation RParenLoc,
453 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek56c864e2007-08-10 21:21:05 +0000454 unsigned format_idx, Expr** Args,
455 unsigned NumArgsInCall);
Ted Kremenekcff94fa2007-08-17 16:46:58 +0000456
457 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
458 SourceLocation ReturnLoc);
459
Anders Carlsson98f07902007-08-17 05:31:46 +0000460
461 bool CheckBuiltinCFStringArgument(Expr* Arg);
Chris Lattner7cee11f2006-11-03 06:42:29 +0000462};
463
464
465} // end namespace clang
Chris Lattner7cee11f2006-11-03 06:42:29 +0000466
467#endif