blob: f0a072eb9b8747083f71b2087637d08036d33085 [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;
32 class Expr;
Steve Naroff9091f3f2007-09-02 15:34:30 +000033 class InitListExpr;
Chris Lattner4b009652007-07-25 00:24:17 +000034 class VarDecl;
35 class ParmVarDecl;
36 class TypedefDecl;
37 class FunctionDecl;
38 class QualType;
Chris Lattner3496d522007-09-04 02:45:27 +000039 struct LangOptions;
40 struct DeclaratorChunk;
Chris Lattner4b009652007-07-25 00:24:17 +000041 class Token;
42 class IntegerLiteral;
43 class ArrayType;
44 class LabelStmt;
45 class SwitchStmt;
Steve Naroff1b8a46c2007-07-27 22:15:19 +000046 class OCUVectorType;
Steve Naroff82113e32007-07-29 16:33:31 +000047 class TypedefDecl;
48
Chris Lattner4b009652007-07-25 00:24:17 +000049/// Sema - This implements semantic analysis and AST building for C.
50class Sema : public Action {
51 Preprocessor &PP;
52
53 ASTContext &Context;
54
55 /// CurFunctionDecl - If inside of a function body, this contains a pointer to
56 /// the function decl for the function being parsed.
57 FunctionDecl *CurFunctionDecl;
58
59 /// LastInGroupList - This vector is populated when there are multiple
60 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
61 /// all but the last decl will be entered into this. This is used by the
62 /// ASTStreamer.
63 std::vector<Decl*> &LastInGroupList;
64
65 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
66 /// it (which acts like the label decl in some ways). Forward referenced
67 /// labels have a LabelStmt created for them with a null location & SubStmt.
68 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
69
70 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroff82113e32007-07-29 16:33:31 +000071
72 /// OCUVectorDecls - This is a list all the OCU vector types. This allows
73 /// us to associate a raw vector type with one of the OCU type names.
74 /// This is only necessary for issuing pretty diagnostics.
75 llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls;
Chris Lattner2e64c072007-08-10 20:18:51 +000076
77 // Enum values used by KnownFunctionIDs (see below).
78 enum {
79 id_printf,
80 id_fprintf,
81 id_sprintf,
82 id_snprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +000083 id_asprintf,
Ted Kremenek2d7e9532007-08-10 21:13:51 +000084 id_vsnprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +000085 id_vasprintf,
86 id_vfprintf,
87 id_vsprintf,
88 id_vprintf,
89 id_num_known_functions
90 };
91
92 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
93 /// of known functions used by the semantic analysis to do various
94 /// kinds of checking (e.g. checking format string errors in printf calls).
95 /// This list is populated upon the creation of a Sema object.
96 IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
97
Chris Lattner4b009652007-07-25 00:24:17 +000098public:
99 Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
100
101 const LangOptions &getLangOptions() const;
102
103 /// The primitive diagnostic helpers - always returns true, which simplifies
104 /// error handling (i.e. less code).
105 bool Diag(SourceLocation Loc, unsigned DiagID);
106 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
107 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
108 const std::string &Msg2);
109
110 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
111 bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
112 bool Diag(SourceLocation Loc, unsigned DiagID,
113 SourceRange R1, SourceRange R2);
114 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
115 SourceRange R1);
116 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
117 SourceRange R1, SourceRange R2);
118 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
119 const std::string &Msg2, SourceRange R1);
120 bool Diag(SourceLocation Loc, unsigned DiagID,
121 const std::string &Msg1, const std::string &Msg2,
122 SourceRange R1, SourceRange R2);
123
Chris Lattnerb26b7ad2007-08-31 04:53:24 +0000124 virtual void DeleteExpr(ExprTy *E);
125 virtual void DeleteStmt(StmtTy *S);
126
Chris Lattner4b009652007-07-25 00:24:17 +0000127 //===--------------------------------------------------------------------===//
128 // Type Analysis / Processing: SemaType.cpp.
129 //
130 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
131
132 virtual TypeResult ParseTypeName(Scope *S, Declarator &D);
133
134 virtual TypeResult ParseParamDeclaratorType(Scope *S, Declarator &D);
135private:
136 //===--------------------------------------------------------------------===//
137 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
138 //
139 virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
140 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
141 DeclTy *LastInGroup);
142 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
143
144 virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
145 virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
146 virtual void PopScope(SourceLocation Loc, Scope *S);
147
148 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
149 /// no declarator (e.g. "struct foo;") is parsed.
150 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
151
152 virtual DeclTy *ParseTag(Scope *S, unsigned TagType, TagKind TK,
153 SourceLocation KWLoc, IdentifierInfo *Name,
154 SourceLocation NameLoc, AttributeList *Attr);
155 virtual DeclTy *ParseField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart,
156 Declarator &D, ExprTy *BitfieldWidth);
157 virtual void ParseRecordBody(SourceLocation RecLoc, DeclTy *TagDecl,
158 DeclTy **Fields, unsigned NumFields);
Fariborz Jahanian3dc7cbc2007-09-10 20:33:04 +0000159 virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
160 DeclTy **allMethods, unsigned allNum);
Chris Lattner4b009652007-07-25 00:24:17 +0000161 virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
162 DeclTy *LastEnumConstant,
163 SourceLocation IdLoc, IdentifierInfo *Id,
164 SourceLocation EqualLoc, ExprTy *Val);
165 virtual void ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
166 DeclTy **Elements, unsigned NumElements);
167private:
168 /// Subroutines of ParseDeclarator()...
169 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
170 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
171 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old);
172 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
173 /// AddTopLevelDecl - called after the decl has been fully processed.
174 /// Allows for bookkeeping and post-processing of each declaration.
175 void AddTopLevelDecl(Decl *current, Decl *last);
176
177 /// More parsing and symbol table subroutines...
178 ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
179 Scope *FnBodyScope);
180 Decl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc,
181 Scope *S);
182 Decl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
183 Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
184 Scope *S);
185 // Decl attributes - this routine is the top level dispatcher.
186 void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,
187 AttributeList *declarator_postfix);
188 void HandleDeclAttribute(Decl *New, AttributeList *rawAttr);
189
190 // HandleVectorTypeAttribute - this attribute is only applicable to
191 // integral and float scalars, although arrays, pointers, and function
192 // return values are allowed in conjunction with this construct. Aggregates
193 // with this attribute are invalid, even if they are of the same size as a
194 // corresponding scalar.
195 // The raw attribute should contain precisely 1 argument, the vector size
196 // for the variable, measured in bytes. If curType and rawAttr are well
197 // formed, this routine will return a new vector type.
198 QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
Steve Naroff82113e32007-07-29 16:33:31 +0000199 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Chris Lattner4b009652007-07-25 00:24:17 +0000200
201 //===--------------------------------------------------------------------===//
202 // Statement Parsing Callbacks: SemaStmt.cpp.
203public:
204 virtual StmtResult ParseExprStmt(ExprTy *Expr);
205
206 virtual StmtResult ParseNullStmt(SourceLocation SemiLoc);
207 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnerf2b07572007-08-31 21:49:55 +0000208 StmtTy **Elts, unsigned NumElts,
209 bool isStmtExpr);
Chris Lattner4b009652007-07-25 00:24:17 +0000210 virtual StmtResult ParseDeclStmt(DeclTy *Decl);
211 virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
212 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
213 SourceLocation ColonLoc, StmtTy *SubStmt);
214 virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
215 SourceLocation ColonLoc, StmtTy *SubStmt,
216 Scope *CurScope);
217 virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
218 SourceLocation ColonLoc, StmtTy *SubStmt);
219 virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
220 StmtTy *ThenVal, SourceLocation ElseLoc,
221 StmtTy *ElseVal);
222 virtual StmtResult StartSwitchStmt(ExprTy *Cond);
223 virtual StmtResult FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
224 ExprTy *Body);
225 virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
226 StmtTy *Body);
227 virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,
228 SourceLocation WhileLoc, ExprTy *Cond);
229
230 virtual StmtResult ParseForStmt(SourceLocation ForLoc,
231 SourceLocation LParenLoc,
232 StmtTy *First, ExprTy *Second, ExprTy *Third,
233 SourceLocation RParenLoc, StmtTy *Body);
234 virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc,
235 SourceLocation LabelLoc,
236 IdentifierInfo *LabelII);
237 virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
238 SourceLocation StarLoc,
239 ExprTy *DestExp);
240 virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
241 Scope *CurScope);
242 virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
243
244 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
245 ExprTy *RetValExp);
246
247 //===--------------------------------------------------------------------===//
248 // Expression Parsing Callbacks: SemaExpr.cpp.
249
250 // Primary Expressions.
251 virtual ExprResult ParseIdentifierExpr(Scope *S, SourceLocation Loc,
252 IdentifierInfo &II,
253 bool HasTrailingLParen);
254 virtual ExprResult ParsePreDefinedExpr(SourceLocation Loc,
255 tok::TokenKind Kind);
256 virtual ExprResult ParseNumericConstant(const Token &);
257 virtual ExprResult ParseCharacterConstant(const Token &);
258 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
259 ExprTy *Val);
260
261 /// ParseStringLiteral - The specified tokens were lexed as pasted string
262 /// fragments (e.g. "foo" "bar" L"baz").
263 virtual ExprResult ParseStringLiteral(const Token *Toks, unsigned NumToks);
264
265 // Binary/Unary Operators. 'Tok' is the token for the operator.
266 virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
267 ExprTy *Input);
268 virtual ExprResult
269 ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
270 SourceLocation LParenLoc, TypeTy *Ty,
271 SourceLocation RParenLoc);
272
273 virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
274 tok::TokenKind Kind, ExprTy *Input);
275
276 virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
277 ExprTy *Idx, SourceLocation RLoc);
278 virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
279 tok::TokenKind OpKind,
280 SourceLocation MemberLoc,
281 IdentifierInfo &Member);
282
283 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
284 /// This provides the location of the left/right parens and a list of comma
285 /// locations.
286 virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
287 ExprTy **Args, unsigned NumArgs,
288 SourceLocation *CommaLocs,
289 SourceLocation RParenLoc);
290
291 virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
292 SourceLocation RParenLoc, ExprTy *Op);
293
294 virtual ExprResult ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
295 SourceLocation RParenLoc, ExprTy *Op);
296
297 virtual ExprResult ParseInitList(SourceLocation LParenLoc,
298 ExprTy **InitList, unsigned NumInit,
299 SourceLocation RParenLoc);
300
301 virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
302 ExprTy *LHS,ExprTy *RHS);
303
304 /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
305 /// in the case of a the GNU conditional expr extension.
306 virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
307 SourceLocation ColonLoc,
308 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
309
310 /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo".
311 virtual ExprResult ParseAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
312 IdentifierInfo *LabelII);
313
314 virtual ExprResult ParseStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
315 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000316
317 /// __builtin_offsetof(type, a.b[123][456].c)
318 virtual ExprResult ParseBuiltinOffsetOf(SourceLocation BuiltinLoc,
319 SourceLocation TypeLoc, TypeTy *Arg1,
320 OffsetOfComponent *CompPtr,
321 unsigned NumComponents,
322 SourceLocation RParenLoc);
323
Steve Naroff63bad2d2007-08-01 22:05:33 +0000324 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5b528922007-08-01 23:45:51 +0000325 virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +0000326 TypeTy *arg1, TypeTy *arg2,
327 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +0000328
329 // __builtin_choose_expr(constExpr, expr1, expr2)
330 virtual ExprResult ParseChooseExpr(SourceLocation BuiltinLoc,
331 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
332 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000333
334 /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
335 virtual ExprResult ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
336 SourceLocation LAngleBracketLoc, TypeTy *Ty,
337 SourceLocation RAngleBracketLoc,
338 SourceLocation LParenLoc, ExprTy *E,
339 SourceLocation RParenLoc);
340
341 /// ParseCXXBoolLiteral - Parse {true,false} literals.
342 virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
343 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +0000344
345 // ParseObjCStringLiteral - Parse Objective-C string literals.
346 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlsson8be1d402007-08-22 15:14:15 +0000347 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
348 SourceLocation LParenLoc,
349 TypeTy *Ty,
350 SourceLocation RParenLoc);
351
Steve Naroff81f1bba2007-09-06 21:24:23 +0000352 // Objective-C declarations.
353 virtual DeclTy *ObjcStartClassInterface(SourceLocation AtInterafceLoc,
354 IdentifierInfo *ClassName, SourceLocation ClassLoc,
355 IdentifierInfo *SuperName, SourceLocation SuperLoc,
356 IdentifierInfo **ProtocolNames, unsigned NumProtocols,
357 AttributeList *AttrList);
358
359 virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
360 IdentifierInfo **IdentList,
361 unsigned NumElts);
362
Chris Lattner4b009652007-07-25 00:24:17 +0000363private:
364 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
365 // functions and arrays to their respective pointers (C99 6.3.2.1).
366 void UsualUnaryConversions(Expr *&expr);
367
368 // DefaultFunctionArrayConversion - converts functions and arrays
369 // to their respective pointers (C99 6.3.2.1).
370 void DefaultFunctionArrayConversion(Expr *&expr);
371
Steve Naroffdb65e052007-08-28 23:30:39 +0000372 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
373 // do not have a prototype. Integer promotions are performed on each
374 // argument, and arguments that have type float are promoted to double.
375 void DefaultArgumentPromotion(Expr *&expr);
376
Chris Lattner4b009652007-07-25 00:24:17 +0000377 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
378 // operands and then handles various conversions that are common to binary
379 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
380 // routine returns the first non-arithmetic type found. The client is
381 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +0000382 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
383 bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000384 enum AssignmentCheckResult {
385 Compatible,
386 Incompatible,
387 PointerFromInt,
388 IntFromPointer,
389 IncompatiblePointer,
390 CompatiblePointerDiscardsQualifiers
391 };
392 // CheckAssignmentConstraints - Perform type checking for assignment,
393 // argument passing, variable initialization, and function return values.
394 // This routine is only used by the following two methods. C99 6.5.16.
395 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
396
397 // CheckSingleAssignmentConstraints - Currently used by ParseCallExpr,
398 // CheckAssignmentOperands, and ParseReturnStmt. Prior to type checking,
399 // this routine performs the default function/array converions.
400 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
401 Expr *&rExpr);
402 // CheckCompoundAssignmentConstraints - Type check without performing any
403 // conversions. For compound assignments, the "Check...Operands" methods
404 // perform the necessary conversions.
405 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
406 QualType rhs);
407
408 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
409 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
410 QualType rhsType);
411
412 /// the following "Check" methods will return a valid/converted QualType
413 /// or a null QualType (indicating an error diagnostic was issued).
414
415 /// type checking binary operators (subroutines of ParseBinOp).
416 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
417 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
418 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000419 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000420 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000421 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000422 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000423 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000424 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000425 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000426 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +0000427 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +0000428 inline QualType CheckCompareOperands( // C99 6.5.8/9
429 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +0000430 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff8f708362007-08-24 19:07:16 +0000431 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000432 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
433 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
434 // CheckAssignmentOperands is used for both simple and compound assignment.
435 // For simple assignment, pass both expressions and a null converted type.
436 // For compound assignment, pass both expressions and the converted type.
437 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +0000438 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +0000439 inline QualType CheckCommaOperands( // C99 6.5.17
440 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
441 inline QualType CheckConditionalOperands( // C99 6.5.15
442 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
443
444 /// type checking unary operators (subroutines of ParseUnaryOp).
445 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
446 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
447 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
448 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
449 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
450 bool isSizeof);
Chris Lattner5110ad52007-08-24 21:41:10 +0000451 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroff1b8a46c2007-07-27 22:15:19 +0000452
453 /// type checking primary expressions.
454 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
455 IdentifierInfo &Comp, SourceLocation CmpLoc);
456
Steve Naroffe14e5542007-09-02 02:04:30 +0000457 /// type checking declaration initializers (C99 6.7.8)
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000458 bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType,
Steve Naroff1c9de712007-09-03 01:24:23 +0000459 bool isStatic);
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000460 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
461 bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
462 bool isStatic, QualType ElementType);
Steve Naroff509d0b52007-09-04 02:20:04 +0000463 void CheckVariableInitList(QualType DeclType, InitListExpr *IList,
464 QualType ElementType, bool isStatic,
465 int &nInitializers, bool &hadError);
466 void CheckConstantInitList(QualType DeclType, InitListExpr *IList,
467 QualType ElementType, bool isStatic,
468 int &nInitializers, bool &hadError);
469
Chris Lattner3429a812007-08-23 05:46:52 +0000470 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
471 /// the specified width and sign. If an overflow occurs, detect it and emit
472 /// the specified diagnostic.
473 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
474 unsigned NewWidth, bool NewSign,
475 SourceLocation Loc, unsigned DiagID);
476
Chris Lattner2e64c072007-08-10 20:18:51 +0000477 //===--------------------------------------------------------------------===//
478 // Extra semantic analysis beyond the C type system
479 private:
480
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000481 bool CheckFunctionCall(Expr *Fn,
Ted Kremenek081ed872007-08-14 17:39:48 +0000482 SourceLocation LParenLoc, SourceLocation RParenLoc,
483 FunctionDecl *FDecl,
Chris Lattner2e64c072007-08-10 20:18:51 +0000484 Expr** Args, unsigned NumArgsInCall);
485
Ted Kremenek081ed872007-08-14 17:39:48 +0000486 void CheckPrintfArguments(Expr *Fn,
487 SourceLocation LParenLoc, SourceLocation RParenLoc,
488 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek30596542007-08-10 21:21:05 +0000489 unsigned format_idx, Expr** Args,
490 unsigned NumArgsInCall);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000491
492 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
493 SourceLocation ReturnLoc);
494
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000495
496 bool CheckBuiltinCFStringArgument(Expr* Arg);
Chris Lattner4b009652007-07-25 00:24:17 +0000497};
498
499
500} // end namespace clang
501
502#endif