blob: 95b89002ed8a59ef10c8c467006c1568e30c5697 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +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"
Anders Carlssonc1fcb772007-07-22 07:07:56 +000020#include "llvm/ADT/SmallVector.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000021#include <vector>
22#include <string>
23
Chris Lattnerf4021e72007-08-23 05:46:52 +000024namespace llvm {
25 class APSInt;
26}
27
Reid Spencer5f016e22007-07-11 17:01:13 +000028namespace clang {
29 class ASTContext;
30 class Preprocessor;
31 class Decl;
32 class Expr;
Steve Naroff6f9f3072007-09-02 15:34:30 +000033 class InitListExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +000034 class VarDecl;
35 class ParmVarDecl;
36 class TypedefDecl;
37 class FunctionDecl;
38 class QualType;
Chris Lattner701e5eb2007-09-04 02:45:27 +000039 struct LangOptions;
40 struct DeclaratorChunk;
Chris Lattnerd2177732007-07-20 16:59:19 +000041 class Token;
Reid Spencer5f016e22007-07-11 17:01:13 +000042 class IntegerLiteral;
43 class ArrayType;
44 class LabelStmt;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000045 class SwitchStmt;
Steve Naroffe1b31fe2007-07-27 22:15:19 +000046 class OCUVectorType;
Steve Naroffbea0b342007-07-29 16:33:31 +000047 class TypedefDecl;
48
Reid Spencer5f016e22007-07-11 17:01:13 +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;
Anders Carlssonc1fcb772007-07-22 07:07:56 +000069
70 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroffbea0b342007-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 Lattner59907c42007-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 Lattner59907c42007-08-10 20:18:51 +000083 id_asprintf,
Ted Kremeneke0eb80a2007-08-10 21:13:51 +000084 id_vsnprintf,
Chris Lattner59907c42007-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
Reid Spencer5f016e22007-07-11 17:01:13 +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 Lattner394a3fd2007-08-31 04:53:24 +0000124 virtual void DeleteExpr(ExprTy *E);
125 virtual void DeleteStmt(StmtTy *S);
126
Reid Spencer5f016e22007-07-11 17:01:13 +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);
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 Naroffbea0b342007-07-29 16:33:31 +0000197 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Reid Spencer5f016e22007-07-11 17:01:13 +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 Lattner98414c12007-08-31 21:49:55 +0000206 StmtTy **Elts, unsigned NumElts,
207 bool isStmtExpr);
Reid Spencer5f016e22007-07-11 17:01:13 +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,
Chris Lattner6c36be52007-07-18 02:28:47 +0000213 SourceLocation ColonLoc, StmtTy *SubStmt,
214 Scope *CurScope);
Reid Spencer5f016e22007-07-11 17:01:13 +0000215 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);
Anders Carlssonc1fcb772007-07-22 07:07:56 +0000220 virtual StmtResult StartSwitchStmt(ExprTy *Cond);
221 virtual StmtResult FinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
222 ExprTy *Body);
Reid Spencer5f016e22007-07-11 17:01:13 +0000223 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);
Anders Carlsson22742662007-07-21 05:21:51 +0000252 virtual ExprResult ParsePreDefinedExpr(SourceLocation Loc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000253 tok::TokenKind Kind);
Chris Lattnerd2177732007-07-20 16:59:19 +0000254 virtual ExprResult ParseNumericConstant(const Token &);
255 virtual ExprResult ParseCharacterConstant(const Token &);
Reid Spencer5f016e22007-07-11 17:01:13 +0000256 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").
Chris Lattnerd2177732007-07-20 16:59:19 +0000261 virtual ExprResult ParseStringLiteral(const Token *Toks, unsigned NumToks);
Reid Spencer5f016e22007-07-11 17:01:13 +0000262
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);
Steve Naroff4aa88f82007-07-19 01:06:55 +0000291
292 virtual ExprResult ParseCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
293 SourceLocation RParenLoc, ExprTy *Op);
Reid Spencer5f016e22007-07-11 17:01:13 +0000294
Steve Naroff4aa88f82007-07-19 01:06:55 +0000295 virtual ExprResult ParseInitList(SourceLocation LParenLoc,
296 ExprTy **InitList, unsigned NumInit,
297 SourceLocation RParenLoc);
298
Reid Spencer5f016e22007-07-11 17:01:13 +0000299 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
Chris Lattnerab18c4c2007-07-24 16:58:17 +0000312 virtual ExprResult ParseStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
313 SourceLocation RPLoc); // "({..})"
Chris Lattner73d0d4f2007-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 Naroffd34e9152007-08-01 22:05:33 +0000322 // __builtin_types_compatible_p(type1, type2)
Steve Naroff363bcff2007-08-01 23:45:51 +0000323 virtual ExprResult ParseTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroffd34e9152007-08-01 22:05:33 +0000324 TypeTy *arg1, TypeTy *arg2,
325 SourceLocation RPLoc);
Steve Naroffd04fdd52007-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 Lattnerab18c4c2007-07-24 16:58:17 +0000331
Reid Spencer5f016e22007-07-11 17:01:13 +0000332 /// 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 Carlsson55085182007-08-21 17:43:55 +0000342
343 // ParseObjCStringLiteral - Parse Objective-C string literals.
344 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlssonf9bcf012007-08-22 15:14:15 +0000345 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
346 SourceLocation LParenLoc,
347 TypeTy *Ty,
348 SourceLocation RParenLoc);
349
Reid Spencer5f016e22007-07-11 17:01:13 +0000350private:
351 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
Steve Naroffc80b4ee2007-07-16 21:54:35 +0000352 // functions and arrays to their respective pointers (C99 6.3.2.1).
353 void UsualUnaryConversions(Expr *&expr);
354
355 // DefaultFunctionArrayConversion - converts functions and arrays
356 // to their respective pointers (C99 6.3.2.1).
357 void DefaultFunctionArrayConversion(Expr *&expr);
Steve Naroff90045e82007-07-13 23:32:42 +0000358
Steve Naroffb291ab62007-08-28 23:30:39 +0000359 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
360 // do not have a prototype. Integer promotions are performed on each
361 // argument, and arguments that have type float are promoted to double.
362 void DefaultArgumentPromotion(Expr *&expr);
363
Reid Spencer5f016e22007-07-11 17:01:13 +0000364 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
365 // operands and then handles various conversions that are common to binary
366 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
367 // routine returns the first non-arithmetic type found. The client is
368 // responsible for emitting appropriate error diagnostics.
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000369 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
370 bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000371 enum AssignmentCheckResult {
372 Compatible,
373 Incompatible,
374 PointerFromInt,
375 IntFromPointer,
376 IncompatiblePointer,
377 CompatiblePointerDiscardsQualifiers
378 };
Steve Naroff90045e82007-07-13 23:32:42 +0000379 // CheckAssignmentConstraints - Perform type checking for assignment,
380 // argument passing, variable initialization, and function return values.
381 // This routine is only used by the following two methods. C99 6.5.16.
Reid Spencer5f016e22007-07-11 17:01:13 +0000382 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
Steve Naroff90045e82007-07-13 23:32:42 +0000383
384 // CheckSingleAssignmentConstraints - Currently used by ParseCallExpr,
385 // CheckAssignmentOperands, and ParseReturnStmt. Prior to type checking,
386 // this routine performs the default function/array converions.
387 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
388 Expr *&rExpr);
389 // CheckCompoundAssignmentConstraints - Type check without performing any
390 // conversions. For compound assignments, the "Check...Operands" methods
391 // perform the necessary conversions.
392 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
393 QualType rhs);
394
Reid Spencer5f016e22007-07-11 17:01:13 +0000395 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
396 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
397 QualType rhsType);
398
399 /// the following "Check" methods will return a valid/converted QualType
400 /// or a null QualType (indicating an error diagnostic was issued).
401
402 /// type checking binary operators (subroutines of ParseBinOp).
Steve Naroff49b45262007-07-13 16:58:59 +0000403 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
404 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
Reid Spencer5f016e22007-07-11 17:01:13 +0000405 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000406 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000407 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000408 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000409 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000410 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000411 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000412 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000413 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000414 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattnera5937dd2007-08-26 01:18:55 +0000415 inline QualType CheckCompareOperands( // C99 6.5.8/9
416 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Reid Spencer5f016e22007-07-11 17:01:13 +0000417 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff9f5fa9b2007-08-24 19:07:16 +0000418 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Reid Spencer5f016e22007-07-11 17:01:13 +0000419 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
Steve Naroff49b45262007-07-13 16:58:59 +0000420 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000421 // CheckAssignmentOperands is used for both simple and compound assignment.
422 // For simple assignment, pass both expressions and a null converted type.
423 // For compound assignment, pass both expressions and the converted type.
424 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Narofff1120de2007-08-24 22:33:52 +0000425 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Reid Spencer5f016e22007-07-11 17:01:13 +0000426 inline QualType CheckCommaOperands( // C99 6.5.17
Steve Naroff49b45262007-07-13 16:58:59 +0000427 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000428 inline QualType CheckConditionalOperands( // C99 6.5.15
Steve Naroff49b45262007-07-13 16:58:59 +0000429 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
Reid Spencer5f016e22007-07-11 17:01:13 +0000430
431 /// type checking unary operators (subroutines of ParseUnaryOp).
432 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
433 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
434 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
435 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
436 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
437 bool isSizeof);
Chris Lattner5d794252007-08-24 21:41:10 +0000438 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroffe1b31fe2007-07-27 22:15:19 +0000439
440 /// type checking primary expressions.
441 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
442 IdentifierInfo &Comp, SourceLocation CmpLoc);
443
Steve Narofff0090632007-09-02 02:04:30 +0000444 /// type checking declaration initializers (C99 6.7.8)
Steve Naroffd35005e2007-09-03 01:24:23 +0000445 bool CheckInitializer(Expr *simpleInit_or_initList, QualType &declType,
446 bool isStatic);
Steve Narofff0090632007-09-02 02:04:30 +0000447 bool CheckSingleInitializer(Expr *simpleInit, QualType declType);
Steve Naroff371227d2007-09-04 02:20:04 +0000448 bool CheckInitExpr(Expr *expr, bool isStatic, QualType ElementType);
449 void CheckVariableInitList(QualType DeclType, InitListExpr *IList,
450 QualType ElementType, bool isStatic,
451 int &nInitializers, bool &hadError);
452 void CheckConstantInitList(QualType DeclType, InitListExpr *IList,
453 QualType ElementType, bool isStatic,
454 int &nInitializers, bool &hadError);
455
Chris Lattnerf4021e72007-08-23 05:46:52 +0000456 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
457 /// the specified width and sign. If an overflow occurs, detect it and emit
458 /// the specified diagnostic.
459 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
460 unsigned NewWidth, bool NewSign,
461 SourceLocation Loc, unsigned DiagID);
462
Chris Lattner59907c42007-08-10 20:18:51 +0000463 //===--------------------------------------------------------------------===//
464 // Extra semantic analysis beyond the C type system
465 private:
466
Anders Carlsson71993dd2007-08-17 05:31:46 +0000467 bool CheckFunctionCall(Expr *Fn,
Ted Kremenek71895b92007-08-14 17:39:48 +0000468 SourceLocation LParenLoc, SourceLocation RParenLoc,
469 FunctionDecl *FDecl,
Chris Lattner59907c42007-08-10 20:18:51 +0000470 Expr** Args, unsigned NumArgsInCall);
471
Ted Kremenek71895b92007-08-14 17:39:48 +0000472 void CheckPrintfArguments(Expr *Fn,
473 SourceLocation LParenLoc, SourceLocation RParenLoc,
474 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek82077102007-08-10 21:21:05 +0000475 unsigned format_idx, Expr** Args,
476 unsigned NumArgsInCall);
Ted Kremenek06de2762007-08-17 16:46:58 +0000477
478 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
479 SourceLocation ReturnLoc);
480
Anders Carlsson71993dd2007-08-17 05:31:46 +0000481
482 bool CheckBuiltinCFStringArgument(Expr* Arg);
Reid Spencer5f016e22007-07-11 17:01:13 +0000483};
484
485
486} // end namespace clang
487
488#endif