blob: 7a3466f97d32d147fe1a2d453ccc41e0c20a4552 [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;
Steve Naroff6a0e2092007-09-12 14:07:44 +0000140 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
141 void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
Chris Lattner4b009652007-07-25 00:24:17 +0000142 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);
159 virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
160 DeclTy *LastEnumConstant,
161 SourceLocation IdLoc, IdentifierInfo *Id,
162 SourceLocation EqualLoc, ExprTy *Val);
163 virtual void ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
164 DeclTy **Elements, unsigned NumElements);
165private:
166 /// Subroutines of ParseDeclarator()...
167 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
168 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
169 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old);
170 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
171 /// AddTopLevelDecl - called after the decl has been fully processed.
172 /// Allows for bookkeeping and post-processing of each declaration.
173 void AddTopLevelDecl(Decl *current, Decl *last);
174
175 /// More parsing and symbol table subroutines...
176 ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
177 Scope *FnBodyScope);
178 Decl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc,
179 Scope *S);
180 Decl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
181 Decl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
182 Scope *S);
183 // Decl attributes - this routine is the top level dispatcher.
184 void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,
185 AttributeList *declarator_postfix);
186 void HandleDeclAttribute(Decl *New, AttributeList *rawAttr);
187
188 // HandleVectorTypeAttribute - this attribute is only applicable to
189 // integral and float scalars, although arrays, pointers, and function
190 // return values are allowed in conjunction with this construct. Aggregates
191 // with this attribute are invalid, even if they are of the same size as a
192 // corresponding scalar.
193 // The raw attribute should contain precisely 1 argument, the vector size
194 // for the variable, measured in bytes. If curType and rawAttr are well
195 // formed, this routine will return a new vector type.
196 QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
Steve Naroff82113e32007-07-29 16:33:31 +0000197 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Chris Lattner4b009652007-07-25 00:24:17 +0000198
199 //===--------------------------------------------------------------------===//
200 // Statement Parsing Callbacks: SemaStmt.cpp.
201public:
202 virtual StmtResult ParseExprStmt(ExprTy *Expr);
203
204 virtual StmtResult ParseNullStmt(SourceLocation SemiLoc);
205 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnerf2b07572007-08-31 21:49:55 +0000206 StmtTy **Elts, unsigned NumElts,
207 bool isStmtExpr);
Chris Lattner4b009652007-07-25 00:24:17 +0000208 virtual StmtResult ParseDeclStmt(DeclTy *Decl);
209 virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
210 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
211 SourceLocation ColonLoc, StmtTy *SubStmt);
212 virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
213 SourceLocation ColonLoc, StmtTy *SubStmt,
214 Scope *CurScope);
215 virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
216 SourceLocation ColonLoc, StmtTy *SubStmt);
217 virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
218 StmtTy *ThenVal, SourceLocation ElseLoc,
219 StmtTy *ElseVal);
220 virtual StmtResult StartSwitchStmt(ExprTy *Cond);
221 virtual StmtResult FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
222 ExprTy *Body);
223 virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
224 StmtTy *Body);
225 virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,
226 SourceLocation WhileLoc, ExprTy *Cond);
227
228 virtual StmtResult ParseForStmt(SourceLocation ForLoc,
229 SourceLocation LParenLoc,
230 StmtTy *First, ExprTy *Second, ExprTy *Third,
231 SourceLocation RParenLoc, StmtTy *Body);
232 virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc,
233 SourceLocation LabelLoc,
234 IdentifierInfo *LabelII);
235 virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
236 SourceLocation StarLoc,
237 ExprTy *DestExp);
238 virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
239 Scope *CurScope);
240 virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
241
242 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
243 ExprTy *RetValExp);
244
245 //===--------------------------------------------------------------------===//
246 // Expression Parsing Callbacks: SemaExpr.cpp.
247
248 // Primary Expressions.
249 virtual ExprResult ParseIdentifierExpr(Scope *S, SourceLocation Loc,
250 IdentifierInfo &II,
251 bool HasTrailingLParen);
252 virtual ExprResult ParsePreDefinedExpr(SourceLocation Loc,
253 tok::TokenKind Kind);
254 virtual ExprResult ParseNumericConstant(const Token &);
255 virtual ExprResult ParseCharacterConstant(const Token &);
256 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
257 ExprTy *Val);
258
259 /// ParseStringLiteral - The specified tokens were lexed as pasted string
260 /// fragments (e.g. "foo" "bar" L"baz").
261 virtual ExprResult ParseStringLiteral(const Token *Toks, unsigned NumToks);
262
263 // Binary/Unary Operators. 'Tok' is the token for the operator.
264 virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
265 ExprTy *Input);
266 virtual ExprResult
267 ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
268 SourceLocation LParenLoc, TypeTy *Ty,
269 SourceLocation RParenLoc);
270
271 virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
272 tok::TokenKind Kind, ExprTy *Input);
273
274 virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
275 ExprTy *Idx, SourceLocation RLoc);
276 virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
277 tok::TokenKind OpKind,
278 SourceLocation MemberLoc,
279 IdentifierInfo &Member);
280
281 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
282 /// This provides the location of the left/right parens and a list of comma
283 /// locations.
284 virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
285 ExprTy **Args, unsigned NumArgs,
286 SourceLocation *CommaLocs,
287 SourceLocation RParenLoc);
288
289 virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
290 SourceLocation RParenLoc, ExprTy *Op);
291
292 virtual ExprResult ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
293 SourceLocation RParenLoc, ExprTy *Op);
294
295 virtual ExprResult ParseInitList(SourceLocation LParenLoc,
296 ExprTy **InitList, unsigned NumInit,
297 SourceLocation RParenLoc);
298
299 virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
300 ExprTy *LHS,ExprTy *RHS);
301
302 /// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
303 /// in the case of a the GNU conditional expr extension.
304 virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc,
305 SourceLocation ColonLoc,
306 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
307
308 /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo".
309 virtual ExprResult ParseAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
310 IdentifierInfo *LabelII);
311
312 virtual ExprResult ParseStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
313 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000314
315 /// __builtin_offsetof(type, a.b[123][456].c)
316 virtual ExprResult ParseBuiltinOffsetOf(SourceLocation BuiltinLoc,
317 SourceLocation TypeLoc, TypeTy *Arg1,
318 OffsetOfComponent *CompPtr,
319 unsigned NumComponents,
320 SourceLocation RParenLoc);
321
Steve Naroff63bad2d2007-08-01 22:05:33 +0000322 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5b528922007-08-01 23:45:51 +0000323 virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +0000324 TypeTy *arg1, TypeTy *arg2,
325 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +0000326
327 // __builtin_choose_expr(constExpr, expr1, expr2)
328 virtual ExprResult ParseChooseExpr(SourceLocation BuiltinLoc,
329 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
330 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000331
332 /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
333 virtual ExprResult ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
334 SourceLocation LAngleBracketLoc, TypeTy *Ty,
335 SourceLocation RAngleBracketLoc,
336 SourceLocation LParenLoc, ExprTy *E,
337 SourceLocation RParenLoc);
338
339 /// ParseCXXBoolLiteral - Parse {true,false} literals.
340 virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
341 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +0000342
343 // ParseObjCStringLiteral - Parse Objective-C string literals.
344 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlsson8be1d402007-08-22 15:14:15 +0000345 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
346 SourceLocation LParenLoc,
347 TypeTy *Ty,
348 SourceLocation RParenLoc);
349
Steve Naroff81f1bba2007-09-06 21:24:23 +0000350 // Objective-C declarations.
351 virtual DeclTy *ObjcStartClassInterface(SourceLocation AtInterafceLoc,
352 IdentifierInfo *ClassName, SourceLocation ClassLoc,
353 IdentifierInfo *SuperName, SourceLocation SuperLoc,
354 IdentifierInfo **ProtocolNames, unsigned NumProtocols,
355 AttributeList *AttrList);
356
357 virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
358 IdentifierInfo **IdentList,
359 unsigned NumElts);
360
Steve Naroff75494892007-09-11 21:17:26 +0000361 virtual void ObjcAddMethodsToClass(DeclTy *ClassDecl,
362 DeclTy **allMethods, unsigned allNum);
Fariborz Jahanian86f74a42007-09-12 18:23:47 +0000363 virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
364 tok::TokenKind MethodType, TypeTy *ReturnType,
365 ObjcKeywordInfo *Keywords, unsigned NumKeywords,
366 AttributeList *AttrList);
367 virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
368 tok::TokenKind MethodType, TypeTy *ReturnType,
369 IdentifierInfo *SelectorName, AttributeList *AttrList);
Steve Naroff75494892007-09-11 21:17:26 +0000370
Steve Naroff6a0e2092007-09-12 14:07:44 +0000371 virtual void ObjcAddInstanceVariable(DeclTy *ClassDec, DeclTy *Ivar,
Steve Naroff75494892007-09-11 21:17:26 +0000372 tok::ObjCKeywordKind visibility);
Chris Lattner4b009652007-07-25 00:24:17 +0000373private:
374 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
375 // functions and arrays to their respective pointers (C99 6.3.2.1).
376 void UsualUnaryConversions(Expr *&expr);
377
378 // DefaultFunctionArrayConversion - converts functions and arrays
379 // to their respective pointers (C99 6.3.2.1).
380 void DefaultFunctionArrayConversion(Expr *&expr);
381
Steve Naroffdb65e052007-08-28 23:30:39 +0000382 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
383 // do not have a prototype. Integer promotions are performed on each
384 // argument, and arguments that have type float are promoted to double.
385 void DefaultArgumentPromotion(Expr *&expr);
386
Chris Lattner4b009652007-07-25 00:24:17 +0000387 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
388 // operands and then handles various conversions that are common to binary
389 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
390 // routine returns the first non-arithmetic type found. The client is
391 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +0000392 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
393 bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000394 enum AssignmentCheckResult {
395 Compatible,
396 Incompatible,
397 PointerFromInt,
398 IntFromPointer,
399 IncompatiblePointer,
400 CompatiblePointerDiscardsQualifiers
401 };
402 // CheckAssignmentConstraints - Perform type checking for assignment,
403 // argument passing, variable initialization, and function return values.
404 // This routine is only used by the following two methods. C99 6.5.16.
405 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
406
407 // CheckSingleAssignmentConstraints - Currently used by ParseCallExpr,
408 // CheckAssignmentOperands, and ParseReturnStmt. Prior to type checking,
409 // this routine performs the default function/array converions.
410 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
411 Expr *&rExpr);
412 // CheckCompoundAssignmentConstraints - Type check without performing any
413 // conversions. For compound assignments, the "Check...Operands" methods
414 // perform the necessary conversions.
415 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
416 QualType rhs);
417
418 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
419 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
420 QualType rhsType);
421
422 /// the following "Check" methods will return a valid/converted QualType
423 /// or a null QualType (indicating an error diagnostic was issued).
424
425 /// type checking binary operators (subroutines of ParseBinOp).
426 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
427 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
428 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000429 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000430 inline QualType CheckRemainderOperands( // C99 6.5.5
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 CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000433 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000434 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000435 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000436 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +0000437 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +0000438 inline QualType CheckCompareOperands( // C99 6.5.8/9
439 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +0000440 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff8f708362007-08-24 19:07:16 +0000441 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000442 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
443 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
444 // CheckAssignmentOperands is used for both simple and compound assignment.
445 // For simple assignment, pass both expressions and a null converted type.
446 // For compound assignment, pass both expressions and the converted type.
447 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +0000448 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +0000449 inline QualType CheckCommaOperands( // C99 6.5.17
450 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
451 inline QualType CheckConditionalOperands( // C99 6.5.15
452 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
453
454 /// type checking unary operators (subroutines of ParseUnaryOp).
455 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
456 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
457 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
458 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
459 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
460 bool isSizeof);
Chris Lattner5110ad52007-08-24 21:41:10 +0000461 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroff1b8a46c2007-07-27 22:15:19 +0000462
463 /// type checking primary expressions.
464 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
465 IdentifierInfo &Comp, SourceLocation CmpLoc);
466
Steve Naroffe14e5542007-09-02 02:04:30 +0000467 /// type checking declaration initializers (C99 6.7.8)
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000468 bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType,
Steve Naroff1c9de712007-09-03 01:24:23 +0000469 bool isStatic);
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000470 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
471 bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
472 bool isStatic, QualType ElementType);
Steve Naroff509d0b52007-09-04 02:20:04 +0000473 void CheckVariableInitList(QualType DeclType, InitListExpr *IList,
474 QualType ElementType, bool isStatic,
475 int &nInitializers, bool &hadError);
476 void CheckConstantInitList(QualType DeclType, InitListExpr *IList,
477 QualType ElementType, bool isStatic,
478 int &nInitializers, bool &hadError);
479
Chris Lattner3429a812007-08-23 05:46:52 +0000480 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
481 /// the specified width and sign. If an overflow occurs, detect it and emit
482 /// the specified diagnostic.
483 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
484 unsigned NewWidth, bool NewSign,
485 SourceLocation Loc, unsigned DiagID);
486
Chris Lattner2e64c072007-08-10 20:18:51 +0000487 //===--------------------------------------------------------------------===//
488 // Extra semantic analysis beyond the C type system
489 private:
490
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000491 bool CheckFunctionCall(Expr *Fn,
Ted Kremenek081ed872007-08-14 17:39:48 +0000492 SourceLocation LParenLoc, SourceLocation RParenLoc,
493 FunctionDecl *FDecl,
Chris Lattner2e64c072007-08-10 20:18:51 +0000494 Expr** Args, unsigned NumArgsInCall);
495
Ted Kremenek081ed872007-08-14 17:39:48 +0000496 void CheckPrintfArguments(Expr *Fn,
497 SourceLocation LParenLoc, SourceLocation RParenLoc,
498 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek30596542007-08-10 21:21:05 +0000499 unsigned format_idx, Expr** Args,
500 unsigned NumArgsInCall);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000501
502 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
503 SourceLocation ReturnLoc);
504
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000505
506 bool CheckBuiltinCFStringArgument(Expr* Arg);
Chris Lattner4b009652007-07-25 00:24:17 +0000507};
508
509
510} // end namespace clang
511
512#endif