blob: fbf4f53be118e05adeb690ec971c66c47ab082da [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;
33 class VarDecl;
34 class ParmVarDecl;
35 class TypedefDecl;
36 class FunctionDecl;
37 class QualType;
38 class LangOptions;
39 class DeclaratorChunk;
40 class Token;
41 class IntegerLiteral;
42 class ArrayType;
43 class LabelStmt;
44 class SwitchStmt;
Steve Naroff1b8a46c2007-07-27 22:15:19 +000045 class OCUVectorType;
Steve Naroff82113e32007-07-29 16:33:31 +000046 class TypedefDecl;
47
Chris Lattner4b009652007-07-25 00:24:17 +000048/// Sema - This implements semantic analysis and AST building for C.
49class Sema : public Action {
50 Preprocessor &PP;
51
52 ASTContext &Context;
53
54 /// 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
58 /// 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;
63
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.
67 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
68
69 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroff82113e32007-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 Lattner2e64c072007-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 Lattner2e64c072007-08-10 20:18:51 +000082 id_asprintf,
Ted Kremenek2d7e9532007-08-10 21:13:51 +000083 id_vsnprintf,
Chris Lattner2e64c072007-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 Lattner4b009652007-07-25 00:24:17 +000097public:
98 Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
99
100 const LangOptions &getLangOptions() const;
101
102 /// The primitive diagnostic helpers - always returns true, which simplifies
103 /// error handling (i.e. less code).
104 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);
108
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
123 //===--------------------------------------------------------------------===//
124 // Type Analysis / Processing: SemaType.cpp.
125 //
126 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
127
128 virtual TypeResult ParseTypeName(Scope *S, Declarator &D);
129
130 virtual TypeResult ParseParamDeclaratorType(Scope *S, Declarator &D);
131private:
132 //===--------------------------------------------------------------------===//
133 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
134 //
135 virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
136 virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
137 DeclTy *LastInGroup);
138 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
139
140 virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
141 virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
142 virtual void PopScope(SourceLocation Loc, Scope *S);
143
144 /// 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
148 virtual DeclTy *ParseTag(Scope *S, unsigned TagType, TagKind TK,
149 SourceLocation KWLoc, IdentifierInfo *Name,
150 SourceLocation NameLoc, AttributeList *Attr);
151 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);
155 virtual DeclTy *ParseEnumConstant(Scope *S, DeclTy *EnumDecl,
156 DeclTy *LastEnumConstant,
157 SourceLocation IdLoc, IdentifierInfo *Id,
158 SourceLocation EqualLoc, ExprTy *Val);
159 virtual void ParseEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
160 DeclTy **Elements, unsigned NumElements);
161private:
162 /// Subroutines of ParseDeclarator()...
163 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *LastDeclarator);
164 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, Decl *Old);
165 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, Decl *Old);
166 VarDecl *MergeVarDecl(VarDecl *New, Decl *Old);
167 /// 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);
170
171 /// More parsing and symbol table subroutines...
172 ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
173 Scope *FnBodyScope);
174 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);
179 // 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.
192 QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
Steve Naroff82113e32007-07-29 16:33:31 +0000193 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Chris Lattner4b009652007-07-25 00:24:17 +0000194
195 //===--------------------------------------------------------------------===//
196 // Statement Parsing Callbacks: SemaStmt.cpp.
197public:
198 virtual StmtResult ParseExprStmt(ExprTy *Expr);
199
200 virtual StmtResult ParseNullStmt(SourceLocation SemiLoc);
201 virtual StmtResult ParseCompoundStmt(SourceLocation L, SourceLocation R,
202 StmtTy **Elts, unsigned NumElts);
203 virtual StmtResult ParseDeclStmt(DeclTy *Decl);
204 virtual StmtResult ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
205 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
206 SourceLocation ColonLoc, StmtTy *SubStmt);
207 virtual StmtResult ParseDefaultStmt(SourceLocation DefaultLoc,
208 SourceLocation ColonLoc, StmtTy *SubStmt,
209 Scope *CurScope);
210 virtual StmtResult ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
211 SourceLocation ColonLoc, StmtTy *SubStmt);
212 virtual StmtResult ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
213 StmtTy *ThenVal, SourceLocation ElseLoc,
214 StmtTy *ElseVal);
215 virtual StmtResult StartSwitchStmt(ExprTy *Cond);
216 virtual StmtResult FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
217 ExprTy *Body);
218 virtual StmtResult ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
219 StmtTy *Body);
220 virtual StmtResult ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,
221 SourceLocation WhileLoc, ExprTy *Cond);
222
223 virtual StmtResult ParseForStmt(SourceLocation ForLoc,
224 SourceLocation LParenLoc,
225 StmtTy *First, ExprTy *Second, ExprTy *Third,
226 SourceLocation RParenLoc, StmtTy *Body);
227 virtual StmtResult ParseGotoStmt(SourceLocation GotoLoc,
228 SourceLocation LabelLoc,
229 IdentifierInfo *LabelII);
230 virtual StmtResult ParseIndirectGotoStmt(SourceLocation GotoLoc,
231 SourceLocation StarLoc,
232 ExprTy *DestExp);
233 virtual StmtResult ParseContinueStmt(SourceLocation ContinueLoc,
234 Scope *CurScope);
235 virtual StmtResult ParseBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
236
237 virtual StmtResult ParseReturnStmt(SourceLocation ReturnLoc,
238 ExprTy *RetValExp);
239
240 //===--------------------------------------------------------------------===//
241 // Expression Parsing Callbacks: SemaExpr.cpp.
242
243 // Primary Expressions.
244 virtual ExprResult ParseIdentifierExpr(Scope *S, SourceLocation Loc,
245 IdentifierInfo &II,
246 bool HasTrailingLParen);
247 virtual ExprResult ParsePreDefinedExpr(SourceLocation Loc,
248 tok::TokenKind Kind);
249 virtual ExprResult ParseNumericConstant(const Token &);
250 virtual ExprResult ParseCharacterConstant(const Token &);
251 virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
252 ExprTy *Val);
253
254 /// ParseStringLiteral - The specified tokens were lexed as pasted string
255 /// fragments (e.g. "foo" "bar" L"baz").
256 virtual ExprResult ParseStringLiteral(const Token *Toks, unsigned NumToks);
257
258 // 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);
286
287 virtual ExprResult ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
288 SourceLocation RParenLoc, ExprTy *Op);
289
290 virtual ExprResult ParseInitList(SourceLocation LParenLoc,
291 ExprTy **InitList, unsigned NumInit,
292 SourceLocation RParenLoc);
293
294 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);
302
303 /// ParseAddrLabel - Parse the GNU address of label extension: "&&foo".
304 virtual ExprResult ParseAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
305 IdentifierInfo *LabelII);
306
307 virtual ExprResult ParseStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
308 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000309
310 /// __builtin_offsetof(type, a.b[123][456].c)
311 virtual ExprResult ParseBuiltinOffsetOf(SourceLocation BuiltinLoc,
312 SourceLocation TypeLoc, TypeTy *Arg1,
313 OffsetOfComponent *CompPtr,
314 unsigned NumComponents,
315 SourceLocation RParenLoc);
316
Steve Naroff63bad2d2007-08-01 22:05:33 +0000317 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5b528922007-08-01 23:45:51 +0000318 virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +0000319 TypeTy *arg1, TypeTy *arg2,
320 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +0000321
322 // __builtin_choose_expr(constExpr, expr1, expr2)
323 virtual ExprResult ParseChooseExpr(SourceLocation BuiltinLoc,
324 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
325 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000326
327 /// ParseCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
328 virtual ExprResult ParseCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
329 SourceLocation LAngleBracketLoc, TypeTy *Ty,
330 SourceLocation RAngleBracketLoc,
331 SourceLocation LParenLoc, ExprTy *E,
332 SourceLocation RParenLoc);
333
334 /// ParseCXXBoolLiteral - Parse {true,false} literals.
335 virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
336 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +0000337
338 // ParseObjCStringLiteral - Parse Objective-C string literals.
339 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlsson8be1d402007-08-22 15:14:15 +0000340 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
341 SourceLocation LParenLoc,
342 TypeTy *Ty,
343 SourceLocation RParenLoc);
344
Chris Lattner4b009652007-07-25 00:24:17 +0000345private:
346 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
347 // functions and arrays to their respective pointers (C99 6.3.2.1).
348 void UsualUnaryConversions(Expr *&expr);
349
350 // DefaultFunctionArrayConversion - converts functions and arrays
351 // to their respective pointers (C99 6.3.2.1).
352 void DefaultFunctionArrayConversion(Expr *&expr);
353
Steve Naroffdb65e052007-08-28 23:30:39 +0000354 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
355 // do not have a prototype. Integer promotions are performed on each
356 // argument, and arguments that have type float are promoted to double.
357 void DefaultArgumentPromotion(Expr *&expr);
358
Chris Lattner4b009652007-07-25 00:24:17 +0000359 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
360 // operands and then handles various conversions that are common to binary
361 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
362 // routine returns the first non-arithmetic type found. The client is
363 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +0000364 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
365 bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000366 enum AssignmentCheckResult {
367 Compatible,
368 Incompatible,
369 PointerFromInt,
370 IntFromPointer,
371 IncompatiblePointer,
372 CompatiblePointerDiscardsQualifiers
373 };
374 // CheckAssignmentConstraints - Perform type checking for assignment,
375 // argument passing, variable initialization, and function return values.
376 // This routine is only used by the following two methods. C99 6.5.16.
377 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
378
379 // CheckSingleAssignmentConstraints - Currently used by ParseCallExpr,
380 // CheckAssignmentOperands, and ParseReturnStmt. Prior to type checking,
381 // this routine performs the default function/array converions.
382 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
383 Expr *&rExpr);
384 // CheckCompoundAssignmentConstraints - Type check without performing any
385 // conversions. For compound assignments, the "Check...Operands" methods
386 // perform the necessary conversions.
387 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
388 QualType rhs);
389
390 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
391 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
392 QualType rhsType);
393
394 /// the following "Check" methods will return a valid/converted QualType
395 /// or a null QualType (indicating an error diagnostic was issued).
396
397 /// type checking binary operators (subroutines of ParseBinOp).
398 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
399 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
400 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000401 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000402 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000403 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000404 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000405 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000406 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000407 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000408 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +0000409 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +0000410 inline QualType CheckCompareOperands( // C99 6.5.8/9
411 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +0000412 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff8f708362007-08-24 19:07:16 +0000413 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000414 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
415 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
416 // CheckAssignmentOperands is used for both simple and compound assignment.
417 // For simple assignment, pass both expressions and a null converted type.
418 // For compound assignment, pass both expressions and the converted type.
419 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +0000420 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +0000421 inline QualType CheckCommaOperands( // C99 6.5.17
422 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
423 inline QualType CheckConditionalOperands( // C99 6.5.15
424 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
425
426 /// type checking unary operators (subroutines of ParseUnaryOp).
427 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
428 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
429 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
430 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
431 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
432 bool isSizeof);
Chris Lattner5110ad52007-08-24 21:41:10 +0000433 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroff1b8a46c2007-07-27 22:15:19 +0000434
435 /// type checking primary expressions.
436 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
437 IdentifierInfo &Comp, SourceLocation CmpLoc);
438
Chris Lattner4b009652007-07-25 00:24:17 +0000439 /// C99: 6.7.5p3: Used by ParseDeclarator/ParseField to make sure we have
440 /// a constant expression of type int with a value greater than zero. If the
441 /// array has an incomplete type or a valid constant size, return false,
442 /// otherwise emit a diagnostic and return true.
Chris Lattner2e64c072007-08-10 20:18:51 +0000443 bool VerifyConstantArrayType(const ArrayType *ary, SourceLocation loc);
444
Chris Lattner3429a812007-08-23 05:46:52 +0000445 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
446 /// the specified width and sign. If an overflow occurs, detect it and emit
447 /// the specified diagnostic.
448 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
449 unsigned NewWidth, bool NewSign,
450 SourceLocation Loc, unsigned DiagID);
451
Chris Lattner2e64c072007-08-10 20:18:51 +0000452 //===--------------------------------------------------------------------===//
453 // Extra semantic analysis beyond the C type system
454 private:
455
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000456 bool CheckFunctionCall(Expr *Fn,
Ted Kremenek081ed872007-08-14 17:39:48 +0000457 SourceLocation LParenLoc, SourceLocation RParenLoc,
458 FunctionDecl *FDecl,
Chris Lattner2e64c072007-08-10 20:18:51 +0000459 Expr** Args, unsigned NumArgsInCall);
460
Ted Kremenek081ed872007-08-14 17:39:48 +0000461 void CheckPrintfArguments(Expr *Fn,
462 SourceLocation LParenLoc, SourceLocation RParenLoc,
463 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek30596542007-08-10 21:21:05 +0000464 unsigned format_idx, Expr** Args,
465 unsigned NumArgsInCall);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000466
467 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
468 SourceLocation ReturnLoc);
469
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000470
471 bool CheckBuiltinCFStringArgument(Expr* Arg);
Chris Lattner4b009652007-07-25 00:24:17 +0000472};
473
474
475} // end namespace clang
476
477#endif