blob: 2c753f3aa5264649bfa1b6a49389988e697e19ed [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;
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +000049 class ObjcInterfaceDecl;
Steve Naroff82113e32007-07-29 16:33:31 +000050
Chris Lattner4b009652007-07-25 00:24:17 +000051/// Sema - This implements semantic analysis and AST building for C.
52class Sema : public Action {
53 Preprocessor &PP;
54
55 ASTContext &Context;
56
57 /// CurFunctionDecl - If inside of a function body, this contains a pointer to
58 /// the function decl for the function being parsed.
59 FunctionDecl *CurFunctionDecl;
60
61 /// LastInGroupList - This vector is populated when there are multiple
62 /// declarators in a single decl group (e.g. "int A, B, C"). In this case,
63 /// all but the last decl will be entered into this. This is used by the
64 /// ASTStreamer.
65 std::vector<Decl*> &LastInGroupList;
66
67 /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
68 /// it (which acts like the label decl in some ways). Forward referenced
69 /// labels have a LabelStmt created for them with a null location & SubStmt.
70 llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
71
72 llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
Steve Naroff82113e32007-07-29 16:33:31 +000073
74 /// OCUVectorDecls - This is a list all the OCU vector types. This allows
75 /// us to associate a raw vector type with one of the OCU type names.
76 /// This is only necessary for issuing pretty diagnostics.
77 llvm::SmallVector<TypedefDecl*, 24> OCUVectorDecls;
Chris Lattner2e64c072007-08-10 20:18:51 +000078
79 // Enum values used by KnownFunctionIDs (see below).
80 enum {
81 id_printf,
82 id_fprintf,
83 id_sprintf,
84 id_snprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +000085 id_asprintf,
Ted Kremenek2d7e9532007-08-10 21:13:51 +000086 id_vsnprintf,
Chris Lattner2e64c072007-08-10 20:18:51 +000087 id_vasprintf,
88 id_vfprintf,
89 id_vsprintf,
90 id_vprintf,
91 id_num_known_functions
92 };
93
94 /// KnownFunctionIDs - This is a list of IdentifierInfo objects to a set
95 /// of known functions used by the semantic analysis to do various
96 /// kinds of checking (e.g. checking format string errors in printf calls).
97 /// This list is populated upon the creation of a Sema object.
98 IdentifierInfo* KnownFunctionIDs[ id_num_known_functions ];
99
Chris Lattner4b009652007-07-25 00:24:17 +0000100public:
101 Sema(Preprocessor &pp, ASTContext &ctxt, std::vector<Decl*> &prevInGroup);
102
103 const LangOptions &getLangOptions() const;
104
105 /// The primitive diagnostic helpers - always returns true, which simplifies
106 /// error handling (i.e. less code).
107 bool Diag(SourceLocation Loc, unsigned DiagID);
108 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg);
109 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
110 const std::string &Msg2);
111
112 /// More expressive diagnostic helpers for expressions (say that 6 times:-)
113 bool Diag(SourceLocation Loc, unsigned DiagID, SourceRange R1);
114 bool Diag(SourceLocation Loc, unsigned DiagID,
115 SourceRange R1, SourceRange R2);
116 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
117 SourceRange R1);
118 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg,
119 SourceRange R1, SourceRange R2);
120 bool Diag(SourceLocation Loc, unsigned DiagID, const std::string &Msg1,
121 const std::string &Msg2, SourceRange R1);
122 bool Diag(SourceLocation Loc, unsigned DiagID,
123 const std::string &Msg1, const std::string &Msg2,
124 SourceRange R1, SourceRange R2);
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000125
Chris Lattnerb26b7ad2007-08-31 04:53:24 +0000126 virtual void DeleteExpr(ExprTy *E);
127 virtual void DeleteStmt(StmtTy *S);
128
Chris Lattner4b009652007-07-25 00:24:17 +0000129 //===--------------------------------------------------------------------===//
130 // Type Analysis / Processing: SemaType.cpp.
131 //
132 QualType GetTypeForDeclarator(Declarator &D, Scope *S);
133
Steve Naroff0acc9c92007-09-15 18:49:24 +0000134 virtual TypeResult ActOnTypeName(Scope *S, Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000135
Steve Naroff0acc9c92007-09-15 18:49:24 +0000136 virtual TypeResult ActOnParamDeclaratorType(Scope *S, Declarator &D);
Chris Lattner4b009652007-07-25 00:24:17 +0000137private:
138 //===--------------------------------------------------------------------===//
139 // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
140 //
141 virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
Steve Naroff0acc9c92007-09-15 18:49:24 +0000142 virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup);
Steve Naroff6a0e2092007-09-12 14:07:44 +0000143 void AddInitializerToDecl(DeclTy *dcl, ExprTy *init);
Chris Lattner4b009652007-07-25 00:24:17 +0000144 virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group);
145
146 virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D);
147 virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
148 virtual void PopScope(SourceLocation Loc, Scope *S);
149
150 /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
151 /// no declarator (e.g. "struct foo;") is parsed.
152 virtual DeclTy *ParsedFreeStandingDeclSpec(Scope *S, DeclSpec &DS);
153
Steve Naroff0acc9c92007-09-15 18:49:24 +0000154 virtual DeclTy *ActOnTag(Scope *S, unsigned TagType, TagKind TK,
Chris Lattner4b009652007-07-25 00:24:17 +0000155 SourceLocation KWLoc, IdentifierInfo *Name,
156 SourceLocation NameLoc, AttributeList *Attr);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000157 virtual DeclTy *ActOnField(Scope *S, DeclTy *TagDecl,SourceLocation DeclStart,
Chris Lattner4b009652007-07-25 00:24:17 +0000158 Declarator &D, ExprTy *BitfieldWidth);
Steve Naroffffeaa552007-09-14 23:09:53 +0000159
160 // This is used for both record definitions and ObjC interface declarations.
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000161 virtual void ActOnFields(Scope* S,
162 SourceLocation RecLoc, DeclTy *TagDecl,
Steve Naroffffeaa552007-09-14 23:09:53 +0000163 DeclTy **Fields, unsigned NumFields,
164 tok::ObjCKeywordKind *visibility = 0);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000165 virtual DeclTy *ActOnEnumConstant(Scope *S, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000166 DeclTy *LastEnumConstant,
167 SourceLocation IdLoc, IdentifierInfo *Id,
168 SourceLocation EqualLoc, ExprTy *Val);
Steve Naroff0acc9c92007-09-15 18:49:24 +0000169 virtual void ActOnEnumBody(SourceLocation EnumLoc, DeclTy *EnumDecl,
Chris Lattner4b009652007-07-25 00:24:17 +0000170 DeclTy **Elements, unsigned NumElements);
171private:
Steve Naroff0acc9c92007-09-15 18:49:24 +0000172 /// Subroutines of ActOnDeclarator()...
Steve Naroff2591e1b2007-09-13 23:52:58 +0000173 TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl);
Steve Naroffcb597472007-09-13 21:41:19 +0000174 TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
175 FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
176 VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);
Chris Lattner4b009652007-07-25 00:24:17 +0000177 /// AddTopLevelDecl - called after the decl has been fully processed.
178 /// Allows for bookkeeping and post-processing of each declaration.
179 void AddTopLevelDecl(Decl *current, Decl *last);
180
181 /// More parsing and symbol table subroutines...
182 ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo,
183 Scope *FnBodyScope);
Steve Naroffd21bc0d2007-09-13 18:10:37 +0000184 ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI,
185 SourceLocation IdLoc, Scope *S);
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000186 ObjcInterfaceDecl *getObjCInterfaceDecl(Scope *S,
187 IdentifierInfo *Id, SourceLocation IdLoc);
Steve Naroffd21bc0d2007-09-13 18:10:37 +0000188 ScopedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, Scope *S);
Steve Narofff0c31dd2007-09-16 16:16:00 +0000189 ScopedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,
Chris Lattner4b009652007-07-25 00:24:17 +0000190 Scope *S);
191 // Decl attributes - this routine is the top level dispatcher.
192 void HandleDeclAttributes(Decl *New, AttributeList *declspec_prefix,
193 AttributeList *declarator_postfix);
194 void HandleDeclAttribute(Decl *New, AttributeList *rawAttr);
195
196 // HandleVectorTypeAttribute - this attribute is only applicable to
197 // integral and float scalars, although arrays, pointers, and function
198 // return values are allowed in conjunction with this construct. Aggregates
199 // with this attribute are invalid, even if they are of the same size as a
200 // corresponding scalar.
201 // The raw attribute should contain precisely 1 argument, the vector size
202 // for the variable, measured in bytes. If curType and rawAttr are well
203 // formed, this routine will return a new vector type.
204 QualType HandleVectorTypeAttribute(QualType curType, AttributeList *rawAttr);
Steve Naroff82113e32007-07-29 16:33:31 +0000205 void HandleOCUVectorTypeAttribute(TypedefDecl *d, AttributeList *rawAttr);
Chris Lattner4b009652007-07-25 00:24:17 +0000206
207 //===--------------------------------------------------------------------===//
208 // Statement Parsing Callbacks: SemaStmt.cpp.
209public:
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000210 virtual StmtResult ActOnExprStmt(ExprTy *Expr);
Chris Lattner4b009652007-07-25 00:24:17 +0000211
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000212 virtual StmtResult ActOnNullStmt(SourceLocation SemiLoc);
213 virtual StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnerf2b07572007-08-31 21:49:55 +0000214 StmtTy **Elts, unsigned NumElts,
215 bool isStmtExpr);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000216 virtual StmtResult ActOnDeclStmt(DeclTy *Decl);
217 virtual StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal,
Chris Lattner4b009652007-07-25 00:24:17 +0000218 SourceLocation DotDotDotLoc, ExprTy *RHSVal,
219 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000220 virtual StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000221 SourceLocation ColonLoc, StmtTy *SubStmt,
222 Scope *CurScope);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000223 virtual StmtResult ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Chris Lattner4b009652007-07-25 00:24:17 +0000224 SourceLocation ColonLoc, StmtTy *SubStmt);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000225 virtual StmtResult ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Chris Lattner4b009652007-07-25 00:24:17 +0000226 StmtTy *ThenVal, SourceLocation ElseLoc,
227 StmtTy *ElseVal);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000228 virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
229 virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
Chris Lattner4b009652007-07-25 00:24:17 +0000230 ExprTy *Body);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000231 virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
Chris Lattner4b009652007-07-25 00:24:17 +0000232 StmtTy *Body);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000233 virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner4b009652007-07-25 00:24:17 +0000234 SourceLocation WhileLoc, ExprTy *Cond);
235
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000236 virtual StmtResult ActOnForStmt(SourceLocation ForLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000237 SourceLocation LParenLoc,
238 StmtTy *First, ExprTy *Second, ExprTy *Third,
239 SourceLocation RParenLoc, StmtTy *Body);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000240 virtual StmtResult ActOnGotoStmt(SourceLocation GotoLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000241 SourceLocation LabelLoc,
242 IdentifierInfo *LabelII);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000243 virtual StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000244 SourceLocation StarLoc,
245 ExprTy *DestExp);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000246 virtual StmtResult ActOnContinueStmt(SourceLocation ContinueLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000247 Scope *CurScope);
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000248 virtual StmtResult ActOnBreakStmt(SourceLocation GotoLoc, Scope *CurScope);
Chris Lattner4b009652007-07-25 00:24:17 +0000249
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000250 virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000251 ExprTy *RetValExp);
252
253 //===--------------------------------------------------------------------===//
254 // Expression Parsing Callbacks: SemaExpr.cpp.
255
256 // Primary Expressions.
Steve Naroff0acc9c92007-09-15 18:49:24 +0000257 virtual ExprResult ActOnIdentifierExpr(Scope *S, SourceLocation Loc,
Chris Lattner4b009652007-07-25 00:24:17 +0000258 IdentifierInfo &II,
259 bool HasTrailingLParen);
Steve Naroff87d58b42007-09-16 03:34:24 +0000260 virtual ExprResult ActOnPreDefinedExpr(SourceLocation Loc,
Chris Lattner4b009652007-07-25 00:24:17 +0000261 tok::TokenKind Kind);
Steve Naroff87d58b42007-09-16 03:34:24 +0000262 virtual ExprResult ActOnNumericConstant(const Token &);
263 virtual ExprResult ActOnCharacterConstant(const Token &);
264 virtual ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R,
Chris Lattner4b009652007-07-25 00:24:17 +0000265 ExprTy *Val);
266
Steve Naroff87d58b42007-09-16 03:34:24 +0000267 /// ActOnStringLiteral - The specified tokens were lexed as pasted string
Chris Lattner4b009652007-07-25 00:24:17 +0000268 /// fragments (e.g. "foo" "bar" L"baz").
Steve Naroff87d58b42007-09-16 03:34:24 +0000269 virtual ExprResult ActOnStringLiteral(const Token *Toks, unsigned NumToks);
Chris Lattner4b009652007-07-25 00:24:17 +0000270
271 // Binary/Unary Operators. 'Tok' is the token for the operator.
Steve Naroff87d58b42007-09-16 03:34:24 +0000272 virtual ExprResult ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
Chris Lattner4b009652007-07-25 00:24:17 +0000273 ExprTy *Input);
274 virtual ExprResult
Steve Naroff87d58b42007-09-16 03:34:24 +0000275 ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
Chris Lattner4b009652007-07-25 00:24:17 +0000276 SourceLocation LParenLoc, TypeTy *Ty,
277 SourceLocation RParenLoc);
278
Steve Naroff87d58b42007-09-16 03:34:24 +0000279 virtual ExprResult ActOnPostfixUnaryOp(SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000280 tok::TokenKind Kind, ExprTy *Input);
281
Steve Naroff87d58b42007-09-16 03:34:24 +0000282 virtual ExprResult ActOnArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000283 ExprTy *Idx, SourceLocation RLoc);
Steve Naroff87d58b42007-09-16 03:34:24 +0000284 virtual ExprResult ActOnMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000285 tok::TokenKind OpKind,
286 SourceLocation MemberLoc,
287 IdentifierInfo &Member);
288
Steve Naroff87d58b42007-09-16 03:34:24 +0000289 /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Chris Lattner4b009652007-07-25 00:24:17 +0000290 /// This provides the location of the left/right parens and a list of comma
291 /// locations.
Steve Naroff87d58b42007-09-16 03:34:24 +0000292 virtual ExprResult ActOnCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000293 ExprTy **Args, unsigned NumArgs,
294 SourceLocation *CommaLocs,
295 SourceLocation RParenLoc);
296
Steve Naroff87d58b42007-09-16 03:34:24 +0000297 virtual ExprResult ActOnCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner4b009652007-07-25 00:24:17 +0000298 SourceLocation RParenLoc, ExprTy *Op);
299
Steve Naroff87d58b42007-09-16 03:34:24 +0000300 virtual ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, TypeTy *Ty,
Chris Lattner4b009652007-07-25 00:24:17 +0000301 SourceLocation RParenLoc, ExprTy *Op);
302
Steve Naroff87d58b42007-09-16 03:34:24 +0000303 virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000304 ExprTy **InitList, unsigned NumInit,
305 SourceLocation RParenLoc);
306
Steve Naroff87d58b42007-09-16 03:34:24 +0000307 virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
Chris Lattner4b009652007-07-25 00:24:17 +0000308 ExprTy *LHS,ExprTy *RHS);
309
Steve Naroff87d58b42007-09-16 03:34:24 +0000310 /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Chris Lattner4b009652007-07-25 00:24:17 +0000311 /// in the case of a the GNU conditional expr extension.
Steve Naroff87d58b42007-09-16 03:34:24 +0000312 virtual ExprResult ActOnConditionalOp(SourceLocation QuestionLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000313 SourceLocation ColonLoc,
314 ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
315
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000316 /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
317 virtual ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000318 IdentifierInfo *LabelII);
319
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000320 virtual ExprResult ActOnStmtExpr(SourceLocation LPLoc, StmtTy *SubStmt,
Chris Lattner4b009652007-07-25 00:24:17 +0000321 SourceLocation RPLoc); // "({..})"
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000322
323 /// __builtin_offsetof(type, a.b[123][456].c)
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000324 virtual ExprResult ActOnBuiltinOffsetOf(SourceLocation BuiltinLoc,
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000325 SourceLocation TypeLoc, TypeTy *Arg1,
326 OffsetOfComponent *CompPtr,
327 unsigned NumComponents,
328 SourceLocation RParenLoc);
329
Steve Naroff63bad2d2007-08-01 22:05:33 +0000330 // __builtin_types_compatible_p(type1, type2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000331 virtual ExprResult ActOnTypesCompatibleExpr(SourceLocation BuiltinLoc,
Steve Naroff63bad2d2007-08-01 22:05:33 +0000332 TypeTy *arg1, TypeTy *arg2,
333 SourceLocation RPLoc);
Steve Naroff93c53012007-08-03 21:21:27 +0000334
335 // __builtin_choose_expr(constExpr, expr1, expr2)
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000336 virtual ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc,
Steve Naroff93c53012007-08-03 21:21:27 +0000337 ExprTy *cond, ExprTy *expr1, ExprTy *expr2,
338 SourceLocation RPLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000339
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000340 /// ActOnCXXCasts - Parse {dynamic,static,reinterpret,const}_cast's.
341 virtual ExprResult ActOnCXXCasts(SourceLocation OpLoc, tok::TokenKind Kind,
Chris Lattner4b009652007-07-25 00:24:17 +0000342 SourceLocation LAngleBracketLoc, TypeTy *Ty,
343 SourceLocation RAngleBracketLoc,
344 SourceLocation LParenLoc, ExprTy *E,
345 SourceLocation RParenLoc);
346
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000347 /// ActOnCXXBoolLiteral - Parse {true,false} literals.
348 virtual ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000349 tok::TokenKind Kind);
Anders Carlssona66cad42007-08-21 17:43:55 +0000350
351 // ParseObjCStringLiteral - Parse Objective-C string literals.
352 virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
Anders Carlsson8be1d402007-08-22 15:14:15 +0000353 virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
354 SourceLocation LParenLoc,
355 TypeTy *Ty,
356 SourceLocation RParenLoc);
357
Steve Naroff81f1bba2007-09-06 21:24:23 +0000358 // Objective-C declarations.
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000359 virtual DeclTy *ObjcStartClassInterface(Scope* S,
360 SourceLocation AtInterafceLoc,
Steve Naroff81f1bba2007-09-06 21:24:23 +0000361 IdentifierInfo *ClassName, SourceLocation ClassLoc,
362 IdentifierInfo *SuperName, SourceLocation SuperLoc,
363 IdentifierInfo **ProtocolNames, unsigned NumProtocols,
364 AttributeList *AttrList);
365
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000366 virtual DeclTy *ObjcStartProtoInterface(Scope* S,
367 SourceLocation AtProtoInterfaceLoc,
Fariborz Jahanian63ca8ae2007-09-17 21:07:36 +0000368 IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc,
369 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
370
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000371 virtual DeclTy *ObjcStartCatInterface(Scope* S,
372 SourceLocation AtInterfaceLoc,
Fariborz Jahanianf25220e2007-09-18 20:26:58 +0000373 IdentifierInfo *ClassName, SourceLocation ClassLoc,
374 IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
375 IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
376
Fariborz Jahanianc091b5d2007-09-25 18:38:09 +0000377 virtual DeclTy *ObjcStartClassImplementation(Scope* S,
378 SourceLocation AtClassImplLoc,
379 IdentifierInfo *ClassName, SourceLocation ClassLoc,
380 IdentifierInfo *SuperClassname,
381 SourceLocation SuperClassLoc);
382
Steve Naroff81f1bba2007-09-06 21:24:23 +0000383 virtual DeclTy *ObjcClassDeclaration(Scope *S, SourceLocation AtClassLoc,
384 IdentifierInfo **IdentList,
385 unsigned NumElts);
Fariborz Jahanianc716c942007-09-21 15:40:54 +0000386
387 virtual DeclTy *ObjcForwardProtocolDeclaration(Scope *S,
388 SourceLocation AtProtocolLoc,
389 IdentifierInfo **IdentList,
390 unsigned NumElts);
Steve Naroff81f1bba2007-09-06 21:24:23 +0000391
Fariborz Jahanian0c5affb2007-09-29 00:54:24 +0000392 virtual void ObjcAddMethodsToClass(Scope* S, DeclTy *ClassDecl,
Steve Naroff75494892007-09-11 21:17:26 +0000393 DeclTy **allMethods, unsigned allNum);
Fariborz Jahaniand34caf92007-09-26 18:27:25 +0000394
395 virtual void ActOnImpleIvarVsClassIvars(DeclTy *ClassDecl,
396 DeclTy **Fields, unsigned NumFields);
397
Fariborz Jahanian8b5ab6f2007-09-18 00:25:23 +0000398 virtual DeclTy *ObjcBuildMethodDeclaration(SourceLocation MethodLoc,
Steve Naroff6cb1d362007-09-28 22:22:11 +0000399 tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000400 // optional arguments. The number of types/arguments is obtained
401 // from the Sel.getNumArgs().
402 TypeTy **ArgTypes, IdentifierInfo **ArgNames,
403 AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind);
Steve Naroffd3f5ee42007-09-17 21:01:15 +0000404
Steve Naroff4ed9d662007-09-27 14:38:14 +0000405 // ActOnClassMessage - used for both unary and keyword messages.
406 // ArgExprs is optional - if it is present, the number of expressions
407 // is obtained from Sel.getNumArgs().
408 virtual ExprResult ActOnClassMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +0000409 IdentifierInfo *receivingClassName, Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000410 SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
411
412 // ActOnInstanceMessage - used for both unary and keyword messages.
413 // ArgExprs is optional - if it is present, the number of expressions
414 // is obtained from Sel.getNumArgs().
415 virtual ExprResult ActOnInstanceMessage(
Steve Naroff6cb1d362007-09-28 22:22:11 +0000416 ExprTy *receiver, Selector Sel,
Steve Naroff4ed9d662007-09-27 14:38:14 +0000417 SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
Chris Lattner4b009652007-07-25 00:24:17 +0000418private:
419 // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
420 // functions and arrays to their respective pointers (C99 6.3.2.1).
421 void UsualUnaryConversions(Expr *&expr);
422
423 // DefaultFunctionArrayConversion - converts functions and arrays
424 // to their respective pointers (C99 6.3.2.1).
425 void DefaultFunctionArrayConversion(Expr *&expr);
426
Steve Naroffdb65e052007-08-28 23:30:39 +0000427 // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that
428 // do not have a prototype. Integer promotions are performed on each
429 // argument, and arguments that have type float are promoted to double.
430 void DefaultArgumentPromotion(Expr *&expr);
431
Chris Lattner4b009652007-07-25 00:24:17 +0000432 // UsualArithmeticConversions - performs the UsualUnaryConversions on it's
433 // operands and then handles various conversions that are common to binary
434 // operators (C99 6.3.1.8). If both operands aren't arithmetic, this
435 // routine returns the first non-arithmetic type found. The client is
436 // responsible for emitting appropriate error diagnostics.
Steve Naroff8f708362007-08-24 19:07:16 +0000437 QualType UsualArithmeticConversions(Expr *&lExpr, Expr *&rExpr,
438 bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000439 enum AssignmentCheckResult {
440 Compatible,
441 Incompatible,
442 PointerFromInt,
443 IntFromPointer,
444 IncompatiblePointer,
445 CompatiblePointerDiscardsQualifiers
446 };
447 // CheckAssignmentConstraints - Perform type checking for assignment,
448 // argument passing, variable initialization, and function return values.
449 // This routine is only used by the following two methods. C99 6.5.16.
450 AssignmentCheckResult CheckAssignmentConstraints(QualType lhs, QualType rhs);
451
Steve Naroff87d58b42007-09-16 03:34:24 +0000452 // CheckSingleAssignmentConstraints - Currently used by ActOnCallExpr,
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000453 // CheckAssignmentOperands, and ActOnReturnStmt. Prior to type checking,
Chris Lattner4b009652007-07-25 00:24:17 +0000454 // this routine performs the default function/array converions.
455 AssignmentCheckResult CheckSingleAssignmentConstraints(QualType lhs,
456 Expr *&rExpr);
457 // CheckCompoundAssignmentConstraints - Type check without performing any
458 // conversions. For compound assignments, the "Check...Operands" methods
459 // perform the necessary conversions.
460 AssignmentCheckResult CheckCompoundAssignmentConstraints(QualType lhs,
461 QualType rhs);
462
463 // Helper function for CheckAssignmentConstraints (C99 6.5.16.1p1)
464 AssignmentCheckResult CheckPointerTypesForAssignment(QualType lhsType,
465 QualType rhsType);
466
467 /// the following "Check" methods will return a valid/converted QualType
468 /// or a null QualType (indicating an error diagnostic was issued).
469
Steve Naroff87d58b42007-09-16 03:34:24 +0000470 /// type checking binary operators (subroutines of ActOnBinOp).
Chris Lattner4b009652007-07-25 00:24:17 +0000471 inline void InvalidOperands(SourceLocation l, Expr *&lex, Expr *&rex);
472 inline QualType CheckVectorOperands(SourceLocation l, Expr *&lex, Expr *&rex);
473 inline QualType CheckMultiplyDivideOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000474 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000475 inline QualType CheckRemainderOperands( // C99 6.5.5
Steve Naroff8f708362007-08-24 19:07:16 +0000476 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000477 inline QualType CheckAdditionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000478 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000479 inline QualType CheckSubtractionOperands( // C99 6.5.6
Steve Naroff8f708362007-08-24 19:07:16 +0000480 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000481 inline QualType CheckShiftOperands( // C99 6.5.7
Steve Naroff8f708362007-08-24 19:07:16 +0000482 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner254f3bc2007-08-26 01:18:55 +0000483 inline QualType CheckCompareOperands( // C99 6.5.8/9
484 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isRelational);
Chris Lattner4b009652007-07-25 00:24:17 +0000485 inline QualType CheckBitwiseOperands( // C99 6.5.[10...12]
Steve Naroff8f708362007-08-24 19:07:16 +0000486 Expr *&lex, Expr *&rex, SourceLocation OpLoc, bool isCompAssign = false);
Chris Lattner4b009652007-07-25 00:24:17 +0000487 inline QualType CheckLogicalOperands( // C99 6.5.[13,14]
488 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
489 // CheckAssignmentOperands is used for both simple and compound assignment.
490 // For simple assignment, pass both expressions and a null converted type.
491 // For compound assignment, pass both expressions and the converted type.
492 inline QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Steve Naroff0f32f432007-08-24 22:33:52 +0000493 Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
Chris Lattner4b009652007-07-25 00:24:17 +0000494 inline QualType CheckCommaOperands( // C99 6.5.17
495 Expr *&lex, Expr *&rex, SourceLocation OpLoc);
496 inline QualType CheckConditionalOperands( // C99 6.5.15
497 Expr *&cond, Expr *&lhs, Expr *&rhs, SourceLocation questionLoc);
498
Steve Naroff87d58b42007-09-16 03:34:24 +0000499 /// type checking unary operators (subroutines of ActOnUnaryOp).
Chris Lattner4b009652007-07-25 00:24:17 +0000500 /// C99 6.5.3.1, 6.5.3.2, 6.5.3.4
501 QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);
502 QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
503 QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
504 QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc,
505 bool isSizeof);
Chris Lattner5110ad52007-08-24 21:41:10 +0000506 QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
Steve Naroff1b8a46c2007-07-27 22:15:19 +0000507
508 /// type checking primary expressions.
509 QualType CheckOCUVectorComponent(QualType baseType, SourceLocation OpLoc,
510 IdentifierInfo &Comp, SourceLocation CmpLoc);
511
Steve Naroffe14e5542007-09-02 02:04:30 +0000512 /// type checking declaration initializers (C99 6.7.8)
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000513 bool CheckInitializer(Expr *&simpleInit_or_initList, QualType &declType,
Steve Naroff1c9de712007-09-03 01:24:23 +0000514 bool isStatic);
Steve Naroffe6a8c9b2007-09-04 14:36:54 +0000515 bool CheckSingleInitializer(Expr *&simpleInit, QualType declType);
516 bool CheckInitExpr(Expr *expr, InitListExpr *IList, unsigned slot,
517 bool isStatic, QualType ElementType);
Steve Naroff509d0b52007-09-04 02:20:04 +0000518 void CheckVariableInitList(QualType DeclType, InitListExpr *IList,
519 QualType ElementType, bool isStatic,
520 int &nInitializers, bool &hadError);
521 void CheckConstantInitList(QualType DeclType, InitListExpr *IList,
522 QualType ElementType, bool isStatic,
523 int &nInitializers, bool &hadError);
524
Chris Lattner3429a812007-08-23 05:46:52 +0000525 /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
526 /// the specified width and sign. If an overflow occurs, detect it and emit
527 /// the specified diagnostic.
528 void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal,
529 unsigned NewWidth, bool NewSign,
530 SourceLocation Loc, unsigned DiagID);
531
Chris Lattner2e64c072007-08-10 20:18:51 +0000532 //===--------------------------------------------------------------------===//
533 // Extra semantic analysis beyond the C type system
534 private:
535
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000536 bool CheckFunctionCall(Expr *Fn,
Ted Kremenek081ed872007-08-14 17:39:48 +0000537 SourceLocation LParenLoc, SourceLocation RParenLoc,
538 FunctionDecl *FDecl,
Chris Lattner2e64c072007-08-10 20:18:51 +0000539 Expr** Args, unsigned NumArgsInCall);
540
Ted Kremenek081ed872007-08-14 17:39:48 +0000541 void CheckPrintfArguments(Expr *Fn,
542 SourceLocation LParenLoc, SourceLocation RParenLoc,
543 bool HasVAListArg, FunctionDecl *FDecl,
Ted Kremenek30596542007-08-10 21:21:05 +0000544 unsigned format_idx, Expr** Args,
545 unsigned NumArgsInCall);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000546
547 void CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
548 SourceLocation ReturnLoc);
549
Anders Carlssone7e7aa22007-08-17 05:31:46 +0000550
551 bool CheckBuiltinCFStringArgument(Expr* Arg);
Chris Lattner4b009652007-07-25 00:24:17 +0000552};
553
554
555} // end namespace clang
556
557#endif