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