blob: e702ce802a38aa8627c79d669a5afaf86fa7bd23 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for statements.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Sema.h"
Chris Lattner3429a812007-08-23 05:46:52 +000015#include "clang/AST/ASTContext.h"
Chris Lattner4b009652007-07-25 00:24:17 +000016#include "clang/AST/Expr.h"
Chris Lattner3429a812007-08-23 05:46:52 +000017#include "clang/AST/Stmt.h"
Chris Lattner4b009652007-07-25 00:24:17 +000018#include "clang/Parse/Scope.h"
Anders Carlsson49dadd62007-11-25 00:25:21 +000019#include "clang/Basic/TargetInfo.h"
Chris Lattner4b009652007-07-25 00:24:17 +000020#include "clang/Basic/Diagnostic.h"
21#include "clang/Basic/LangOptions.h"
Anders Carlsson49dadd62007-11-25 00:25:21 +000022#include "llvm/ADT/SmallString.h"
Chris Lattner4b009652007-07-25 00:24:17 +000023using namespace clang;
24
Steve Naroff5cbb02f2007-09-16 14:56:35 +000025Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) {
Chris Lattner4b009652007-07-25 00:24:17 +000026 Expr *E = static_cast<Expr*>(expr);
Steve Naroff5cbb02f2007-09-16 14:56:35 +000027 assert(E && "ActOnExprStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +000028 return E;
29}
30
31
Steve Naroff5cbb02f2007-09-16 14:56:35 +000032Sema::StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) {
Chris Lattner4b009652007-07-25 00:24:17 +000033 return new NullStmt(SemiLoc);
34}
35
Steve Naroff5cbb02f2007-09-16 14:56:35 +000036Sema::StmtResult Sema::ActOnDeclStmt(DeclTy *decl) {
Steve Naroffcb597472007-09-13 21:41:19 +000037 if (decl) {
38 ScopedDecl *SD = dyn_cast<ScopedDecl>(static_cast<Decl *>(decl));
Steve Naroff5cbb02f2007-09-16 14:56:35 +000039 assert(SD && "Sema::ActOnDeclStmt(): expected ScopedDecl");
Steve Naroffcb597472007-09-13 21:41:19 +000040 return new DeclStmt(SD);
41 } else
Chris Lattner4b009652007-07-25 00:24:17 +000042 return true; // error
43}
44
45Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +000046Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
Chris Lattnerf2b07572007-08-31 21:49:55 +000047 StmtTy **elts, unsigned NumElts, bool isStmtExpr) {
Chris Lattner3ea3b662007-08-27 04:29:41 +000048 Stmt **Elts = reinterpret_cast<Stmt**>(elts);
49 // If we're in C89 mode, check that we don't have any decls after stmts. If
50 // so, emit an extension diagnostic.
51 if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) {
52 // Note that __extension__ can be around a decl.
53 unsigned i = 0;
54 // Skip over all declarations.
55 for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i)
56 /*empty*/;
57
58 // We found the end of the list or a statement. Scan for another declstmt.
59 for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i)
60 /*empty*/;
61
62 if (i != NumElts) {
Steve Naroffcb597472007-09-13 21:41:19 +000063 ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl();
Chris Lattner3ea3b662007-08-27 04:29:41 +000064 Diag(D->getLocation(), diag::ext_mixed_decls_code);
65 }
66 }
Chris Lattnerf2b07572007-08-31 21:49:55 +000067 // Warn about unused expressions in statements.
68 for (unsigned i = 0; i != NumElts; ++i) {
69 Expr *E = dyn_cast<Expr>(Elts[i]);
70 if (!E) continue;
71
72 // Warn about expressions with unused results.
73 if (E->hasLocalSideEffect() || E->getType()->isVoidType())
74 continue;
75
76 // The last expr in a stmt expr really is used.
77 if (isStmtExpr && i == NumElts-1)
78 continue;
79
80 /// DiagnoseDeadExpr - This expression is side-effect free and evaluated in
81 /// a context where the result is unused. Emit a diagnostic to warn about
82 /// this.
83 if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E))
84 Diag(BO->getOperatorLoc(), diag::warn_unused_expr,
85 BO->getLHS()->getSourceRange(), BO->getRHS()->getSourceRange());
86 else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
87 Diag(UO->getOperatorLoc(), diag::warn_unused_expr,
88 UO->getSubExpr()->getSourceRange());
89 else
90 Diag(E->getExprLoc(), diag::warn_unused_expr, E->getSourceRange());
91 }
92
Steve Naroff5d2fff82007-08-31 23:28:33 +000093 return new CompoundStmt(Elts, NumElts, L, R);
Chris Lattner4b009652007-07-25 00:24:17 +000094}
95
96Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +000097Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval,
Chris Lattner4b009652007-07-25 00:24:17 +000098 SourceLocation DotDotDotLoc, ExprTy *rhsval,
99 SourceLocation ColonLoc, StmtTy *subStmt) {
100 Stmt *SubStmt = static_cast<Stmt*>(subStmt);
101 Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval);
102 assert((LHSVal != 0) && "missing expression in case statement");
103
104 SourceLocation ExpLoc;
105 // C99 6.8.4.2p3: The expression shall be an integer constant.
106 if (!LHSVal->isIntegerConstantExpr(Context, &ExpLoc)) {
107 Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr,
108 LHSVal->getSourceRange());
109 return SubStmt;
110 }
111
112 // GCC extension: The expression shall be an integer constant.
113 if (RHSVal && !RHSVal->isIntegerConstantExpr(Context, &ExpLoc)) {
114 Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr,
115 RHSVal->getSourceRange());
Chris Lattner3429a812007-08-23 05:46:52 +0000116 RHSVal = 0; // Recover by just forgetting about it.
Chris Lattner4b009652007-07-25 00:24:17 +0000117 }
118
119 if (SwitchStack.empty()) {
120 Diag(CaseLoc, diag::err_case_not_in_switch);
121 return SubStmt;
122 }
123
Steve Naroff5d2fff82007-08-31 23:28:33 +0000124 CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000125 SwitchStack.back()->addSwitchCase(CS);
126 return CS;
127}
128
129Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000130Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000131 StmtTy *subStmt, Scope *CurScope) {
132 Stmt *SubStmt = static_cast<Stmt*>(subStmt);
133
134 if (SwitchStack.empty()) {
135 Diag(DefaultLoc, diag::err_default_not_in_switch);
136 return SubStmt;
137 }
138
139 DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt);
140 SwitchStack.back()->addSwitchCase(DS);
141
142 return DS;
143}
144
145Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000146Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
Chris Lattner4b009652007-07-25 00:24:17 +0000147 SourceLocation ColonLoc, StmtTy *subStmt) {
148 Stmt *SubStmt = static_cast<Stmt*>(subStmt);
149 // Look up the record for this label identifier.
150 LabelStmt *&LabelDecl = LabelMap[II];
151
152 // If not forward referenced or defined already, just create a new LabelStmt.
153 if (LabelDecl == 0)
154 return LabelDecl = new LabelStmt(IdentLoc, II, SubStmt);
155
156 assert(LabelDecl->getID() == II && "Label mismatch!");
157
158 // Otherwise, this label was either forward reference or multiply defined. If
159 // multiply defined, reject it now.
160 if (LabelDecl->getSubStmt()) {
161 Diag(IdentLoc, diag::err_redefinition_of_label, LabelDecl->getName());
162 Diag(LabelDecl->getIdentLoc(), diag::err_previous_definition);
163 return SubStmt;
164 }
165
166 // Otherwise, this label was forward declared, and we just found its real
167 // definition. Fill in the forward definition and return it.
168 LabelDecl->setIdentLoc(IdentLoc);
169 LabelDecl->setSubStmt(SubStmt);
170 return LabelDecl;
171}
172
173Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000174Sema::ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
Chris Lattner4b009652007-07-25 00:24:17 +0000175 StmtTy *ThenVal, SourceLocation ElseLoc,
176 StmtTy *ElseVal) {
177 Expr *condExpr = (Expr *)CondVal;
Anders Carlsson663733e2007-10-10 20:50:11 +0000178 Stmt *thenStmt = (Stmt *)ThenVal;
179
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000180 assert(condExpr && "ActOnIfStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +0000181
182 DefaultFunctionArrayConversion(condExpr);
183 QualType condType = condExpr->getType();
184
185 if (!condType->isScalarType()) // C99 6.8.4.1p1
186 return Diag(IfLoc, diag::err_typecheck_statement_requires_scalar,
187 condType.getAsString(), condExpr->getSourceRange());
188
Anders Carlsson663733e2007-10-10 20:50:11 +0000189 // Warn if the if block has a null body without an else value.
190 // this helps prevent bugs due to typos, such as
191 // if (condition);
192 // do_stuff();
193 if (!ElseVal) {
194 if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt))
195 Diag(stmt->getSemiLoc(), diag::warn_empty_if_body);
196 }
197
198 return new IfStmt(IfLoc, condExpr, thenStmt, (Stmt*)ElseVal);
Chris Lattner4b009652007-07-25 00:24:17 +0000199}
200
201Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000202Sema::ActOnStartOfSwitchStmt(ExprTy *cond) {
Chris Lattner3429a812007-08-23 05:46:52 +0000203 Expr *Cond = static_cast<Expr*>(cond);
204
205 // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr.
206 UsualUnaryConversions(Cond);
207
208 SwitchStmt *SS = new SwitchStmt(Cond);
Chris Lattner4b009652007-07-25 00:24:17 +0000209 SwitchStack.push_back(SS);
210 return SS;
211}
212
Chris Lattner3429a812007-08-23 05:46:52 +0000213/// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have
214/// the specified width and sign. If an overflow occurs, detect it and emit
215/// the specified diagnostic.
216void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
217 unsigned NewWidth, bool NewSign,
218 SourceLocation Loc,
219 unsigned DiagID) {
220 // Perform a conversion to the promoted condition type if needed.
221 if (NewWidth > Val.getBitWidth()) {
222 // If this is an extension, just do it.
223 llvm::APSInt OldVal(Val);
224 Val.extend(NewWidth);
225
226 // If the input was signed and negative and the output is unsigned,
227 // warn.
228 if (!NewSign && OldVal.isSigned() && OldVal.isNegative())
229 Diag(Loc, DiagID, OldVal.toString(), Val.toString());
230
231 Val.setIsSigned(NewSign);
232 } else if (NewWidth < Val.getBitWidth()) {
233 // If this is a truncation, check for overflow.
234 llvm::APSInt ConvVal(Val);
235 ConvVal.trunc(NewWidth);
Chris Lattner5c039602007-08-23 22:08:35 +0000236 ConvVal.setIsSigned(NewSign);
Chris Lattner3429a812007-08-23 05:46:52 +0000237 ConvVal.extend(Val.getBitWidth());
Chris Lattner5c039602007-08-23 22:08:35 +0000238 ConvVal.setIsSigned(Val.isSigned());
Chris Lattner3429a812007-08-23 05:46:52 +0000239 if (ConvVal != Val)
240 Diag(Loc, DiagID, Val.toString(), ConvVal.toString());
241
242 // Regardless of whether a diagnostic was emitted, really do the
243 // truncation.
244 Val.trunc(NewWidth);
Chris Lattner5c039602007-08-23 22:08:35 +0000245 Val.setIsSigned(NewSign);
Chris Lattner3429a812007-08-23 05:46:52 +0000246 } else if (NewSign != Val.isSigned()) {
247 // Convert the sign to match the sign of the condition. This can cause
248 // overflow as well: unsigned(INTMIN)
249 llvm::APSInt OldVal(Val);
250 Val.setIsSigned(NewSign);
251
252 if (Val.isNegative()) // Sign bit changes meaning.
253 Diag(Loc, DiagID, OldVal.toString(), Val.toString());
254 }
255}
256
Chris Lattner0ab833c2007-08-23 18:29:20 +0000257namespace {
258 struct CaseCompareFunctor {
259 bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS,
260 const llvm::APSInt &RHS) {
261 return LHS.first < RHS;
262 }
Chris Lattner2157f272007-09-03 18:31:57 +0000263 bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS,
264 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
265 return LHS.first < RHS.first;
266 }
Chris Lattner0ab833c2007-08-23 18:29:20 +0000267 bool operator()(const llvm::APSInt &LHS,
268 const std::pair<llvm::APSInt, CaseStmt*> &RHS) {
269 return LHS < RHS.first;
270 }
271 };
272}
273
Chris Lattner766afb82007-09-21 18:15:22 +0000274/// CmpCaseVals - Comparison predicate for sorting case values.
275///
276static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs,
277 const std::pair<llvm::APSInt, CaseStmt*>& rhs) {
278 if (lhs.first < rhs.first)
279 return true;
280
281 if (lhs.first == rhs.first &&
282 lhs.second->getCaseLoc().getRawEncoding()
283 < rhs.second->getCaseLoc().getRawEncoding())
284 return true;
285 return false;
286}
287
Chris Lattner4b009652007-07-25 00:24:17 +0000288Action::StmtResult
Chris Lattner766afb82007-09-21 18:15:22 +0000289Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch,
290 ExprTy *Body) {
Chris Lattner4b009652007-07-25 00:24:17 +0000291 Stmt *BodyStmt = (Stmt*)Body;
292
293 SwitchStmt *SS = SwitchStack.back();
294 assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!");
295
Steve Naroffa610eab2007-09-01 21:08:38 +0000296 SS->setBody(BodyStmt, SwitchLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000297 SwitchStack.pop_back();
298
Chris Lattner3429a812007-08-23 05:46:52 +0000299 Expr *CondExpr = SS->getCond();
300 QualType CondType = CondExpr->getType();
Chris Lattner4b009652007-07-25 00:24:17 +0000301
Chris Lattner3429a812007-08-23 05:46:52 +0000302 if (!CondType->isIntegerType()) { // C99 6.8.4.2p1
Chris Lattner4b009652007-07-25 00:24:17 +0000303 Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer,
Chris Lattner3429a812007-08-23 05:46:52 +0000304 CondType.getAsString(), CondExpr->getSourceRange());
305 return true;
Chris Lattner4b009652007-07-25 00:24:17 +0000306 }
Chris Lattner3429a812007-08-23 05:46:52 +0000307
308 // Get the bitwidth of the switched-on value before promotions. We must
309 // convert the integer case values to this width before comparison.
Hartmut Kaiser612f1742007-09-16 00:04:22 +0000310 unsigned CondWidth =
311 static_cast<unsigned>(Context.getTypeSize(CondType, SwitchLoc));
Chris Lattner3429a812007-08-23 05:46:52 +0000312 bool CondIsSigned = CondType->isSignedIntegerType();
313
314 // Accumulate all of the case values in a vector so that we can sort them
315 // and detect duplicates. This vector contains the APInt for the case after
316 // it has been converted to the condition type.
Chris Lattner0ab833c2007-08-23 18:29:20 +0000317 typedef llvm::SmallVector<std::pair<llvm::APSInt, CaseStmt*>, 64> CaseValsTy;
318 CaseValsTy CaseVals;
Chris Lattner3429a812007-08-23 05:46:52 +0000319
320 // Keep track of any GNU case ranges we see. The APSInt is the low value.
321 std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRanges;
322
323 DefaultStmt *TheDefaultStmt = 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000324
Chris Lattner1a4066d2007-08-23 06:23:56 +0000325 bool CaseListIsErroneous = false;
326
327 for (SwitchCase *SC = SS->getSwitchCaseList(); SC;
Chris Lattner4b009652007-07-25 00:24:17 +0000328 SC = SC->getNextSwitchCase()) {
Chris Lattner1a4066d2007-08-23 06:23:56 +0000329
Chris Lattner4b009652007-07-25 00:24:17 +0000330 if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) {
Chris Lattner3429a812007-08-23 05:46:52 +0000331 if (TheDefaultStmt) {
332 Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined);
333 Diag(TheDefaultStmt->getDefaultLoc(), diag::err_first_label);
Chris Lattner4b009652007-07-25 00:24:17 +0000334
Chris Lattner3429a812007-08-23 05:46:52 +0000335 // FIXME: Remove the default statement from the switch block so that
336 // we'll return a valid AST. This requires recursing down the
337 // AST and finding it, not something we are set up to do right now. For
338 // now, just lop the entire switch stmt out of the AST.
Chris Lattner1a4066d2007-08-23 06:23:56 +0000339 CaseListIsErroneous = true;
Chris Lattner4b009652007-07-25 00:24:17 +0000340 }
Chris Lattner3429a812007-08-23 05:46:52 +0000341 TheDefaultStmt = DS;
Chris Lattner4b009652007-07-25 00:24:17 +0000342
Chris Lattner3429a812007-08-23 05:46:52 +0000343 } else {
344 CaseStmt *CS = cast<CaseStmt>(SC);
345
346 // We already verified that the expression has a i-c-e value (C99
347 // 6.8.4.2p3) - get that value now.
348 llvm::APSInt LoVal(32);
Chris Lattnere992d6c2008-01-16 19:17:22 +0000349 Expr *Lo = CS->getLHS();
350 Lo->isIntegerConstantExpr(LoVal, Context);
Chris Lattner3429a812007-08-23 05:46:52 +0000351
352 // Convert the value to the same width/sign as the condition.
353 ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned,
354 CS->getLHS()->getLocStart(),
355 diag::warn_case_value_overflow);
Chris Lattner4b009652007-07-25 00:24:17 +0000356
Chris Lattnere992d6c2008-01-16 19:17:22 +0000357 // If the LHS is not the same type as the condition, insert an implicit
358 // cast.
359 ImpCastExprToType(Lo, CondType);
360 CS->setLHS(Lo);
361
Chris Lattner1a4066d2007-08-23 06:23:56 +0000362 // If this is a case range, remember it in CaseRanges, otherwise CaseVals.
Chris Lattner3429a812007-08-23 05:46:52 +0000363 if (CS->getRHS())
364 CaseRanges.push_back(std::make_pair(LoVal, CS));
Chris Lattner1a4066d2007-08-23 06:23:56 +0000365 else
366 CaseVals.push_back(std::make_pair(LoVal, CS));
Chris Lattner3429a812007-08-23 05:46:52 +0000367 }
368 }
369
Chris Lattner1a4066d2007-08-23 06:23:56 +0000370 // Sort all the scalar case values so we can easily detect duplicates.
Chris Lattner766afb82007-09-21 18:15:22 +0000371 std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals);
Chris Lattner3429a812007-08-23 05:46:52 +0000372
Chris Lattner2b1b9a82007-08-23 14:29:07 +0000373 if (!CaseVals.empty()) {
374 for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
375 if (CaseVals[i].first == CaseVals[i+1].first) {
376 // If we have a duplicate, report it.
377 Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
378 diag::err_duplicate_case, CaseVals[i].first.toString());
379 Diag(CaseVals[i].second->getLHS()->getLocStart(),
380 diag::err_duplicate_case_prev);
381 // FIXME: We really want to remove the bogus case stmt from the substmt,
382 // but we have no way to do this right now.
383 CaseListIsErroneous = true;
384 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000385 }
386 }
Chris Lattner3429a812007-08-23 05:46:52 +0000387
Chris Lattner1a4066d2007-08-23 06:23:56 +0000388 // Detect duplicate case ranges, which usually don't exist at all in the first
389 // place.
390 if (!CaseRanges.empty()) {
391 // Sort all the case ranges by their low value so we can easily detect
392 // overlaps between ranges.
Chris Lattner0ab833c2007-08-23 18:29:20 +0000393 std::stable_sort(CaseRanges.begin(), CaseRanges.end());
Chris Lattner1a4066d2007-08-23 06:23:56 +0000394
395 // Scan the ranges, computing the high values and removing empty ranges.
396 std::vector<llvm::APSInt> HiVals;
Chris Lattner7443e0f2007-08-23 17:48:14 +0000397 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
Chris Lattner1a4066d2007-08-23 06:23:56 +0000398 CaseStmt *CR = CaseRanges[i].second;
399 llvm::APSInt HiVal(32);
Chris Lattnere992d6c2008-01-16 19:17:22 +0000400 Expr *Hi = CR->getRHS();
401 Hi->isIntegerConstantExpr(HiVal, Context);
Chris Lattner1a4066d2007-08-23 06:23:56 +0000402
403 // Convert the value to the same width/sign as the condition.
404 ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned,
405 CR->getRHS()->getLocStart(),
406 diag::warn_case_value_overflow);
407
Chris Lattnere992d6c2008-01-16 19:17:22 +0000408 // If the LHS is not the same type as the condition, insert an implicit
409 // cast.
410 ImpCastExprToType(Hi, CondType);
411 CR->setRHS(Hi);
412
Chris Lattner7443e0f2007-08-23 17:48:14 +0000413 // If the low value is bigger than the high value, the case is empty.
414 if (CaseRanges[i].first > HiVal) {
415 Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range,
416 SourceRange(CR->getLHS()->getLocStart(),
417 CR->getRHS()->getLocEnd()));
418 CaseRanges.erase(CaseRanges.begin()+i);
419 --i, --e;
420 continue;
421 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000422 HiVals.push_back(HiVal);
423 }
424
425 // Rescan the ranges, looking for overlap with singleton values and other
Chris Lattner0ab833c2007-08-23 18:29:20 +0000426 // ranges. Since the range list is sorted, we only need to compare case
427 // ranges with their neighbors.
Chris Lattner1a4066d2007-08-23 06:23:56 +0000428 for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) {
Chris Lattner0ab833c2007-08-23 18:29:20 +0000429 llvm::APSInt &CRLo = CaseRanges[i].first;
430 llvm::APSInt &CRHi = HiVals[i];
431 CaseStmt *CR = CaseRanges[i].second;
Chris Lattner1a4066d2007-08-23 06:23:56 +0000432
Chris Lattner0ab833c2007-08-23 18:29:20 +0000433 // Check to see whether the case range overlaps with any singleton cases.
434 CaseStmt *OverlapStmt = 0;
435 llvm::APSInt OverlapVal(32);
436
437 // Find the smallest value >= the lower bound. If I is in the case range,
438 // then we have overlap.
439 CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(),
440 CaseVals.end(), CRLo,
441 CaseCompareFunctor());
442 if (I != CaseVals.end() && I->first < CRHi) {
443 OverlapVal = I->first; // Found overlap with scalar.
444 OverlapStmt = I->second;
445 }
446
447 // Find the smallest value bigger than the upper bound.
448 I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor());
449 if (I != CaseVals.begin() && (I-1)->first >= CRLo) {
450 OverlapVal = (I-1)->first; // Found overlap with scalar.
451 OverlapStmt = (I-1)->second;
452 }
453
454 // Check to see if this case stmt overlaps with the subsequent case range.
455 if (i && CRLo <= HiVals[i-1]) {
456 OverlapVal = HiVals[i-1]; // Found overlap with range.
457 OverlapStmt = CaseRanges[i-1].second;
458 }
459
460 if (OverlapStmt) {
461 // If we have a duplicate, report it.
462 Diag(CR->getLHS()->getLocStart(),
463 diag::err_duplicate_case, OverlapVal.toString());
464 Diag(OverlapStmt->getLHS()->getLocStart(),
465 diag::err_duplicate_case_prev);
466 // FIXME: We really want to remove the bogus case stmt from the substmt,
467 // but we have no way to do this right now.
468 CaseListIsErroneous = true;
469 }
Chris Lattner1a4066d2007-08-23 06:23:56 +0000470 }
471 }
Chris Lattner3429a812007-08-23 05:46:52 +0000472
Chris Lattner1a4066d2007-08-23 06:23:56 +0000473 // FIXME: If the case list was broken is some way, we don't have a good system
474 // to patch it up. Instead, just return the whole substmt as broken.
475 if (CaseListIsErroneous)
476 return true;
Chris Lattner3429a812007-08-23 05:46:52 +0000477
Chris Lattner4b009652007-07-25 00:24:17 +0000478 return SS;
479}
480
481Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000482Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body) {
Chris Lattner4b009652007-07-25 00:24:17 +0000483 Expr *condExpr = (Expr *)Cond;
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000484 assert(condExpr && "ActOnWhileStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +0000485
486 DefaultFunctionArrayConversion(condExpr);
487 QualType condType = condExpr->getType();
488
489 if (!condType->isScalarType()) // C99 6.8.5p2
490 return Diag(WhileLoc, diag::err_typecheck_statement_requires_scalar,
491 condType.getAsString(), condExpr->getSourceRange());
492
Steve Naroff5d2fff82007-08-31 23:28:33 +0000493 return new WhileStmt(condExpr, (Stmt*)Body, WhileLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000494}
495
496Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000497Sema::ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
Chris Lattner4b009652007-07-25 00:24:17 +0000498 SourceLocation WhileLoc, ExprTy *Cond) {
499 Expr *condExpr = (Expr *)Cond;
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000500 assert(condExpr && "ActOnDoStmt(): missing expression");
Chris Lattner4b009652007-07-25 00:24:17 +0000501
502 DefaultFunctionArrayConversion(condExpr);
503 QualType condType = condExpr->getType();
504
505 if (!condType->isScalarType()) // C99 6.8.5p2
506 return Diag(DoLoc, diag::err_typecheck_statement_requires_scalar,
507 condType.getAsString(), condExpr->getSourceRange());
508
Steve Naroff5d2fff82007-08-31 23:28:33 +0000509 return new DoStmt((Stmt*)Body, condExpr, DoLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000510}
511
512Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000513Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chris Lattner3332fbd2007-08-28 04:55:47 +0000514 StmtTy *first, ExprTy *second, ExprTy *third,
515 SourceLocation RParenLoc, StmtTy *body) {
516 Stmt *First = static_cast<Stmt*>(first);
517 Expr *Second = static_cast<Expr*>(second);
518 Expr *Third = static_cast<Expr*>(third);
519 Stmt *Body = static_cast<Stmt*>(body);
520
Chris Lattner06611052007-08-28 05:03:08 +0000521 if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) {
522 // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
523 // identifiers for objects having storage class 'auto' or 'register'.
Steve Naroff2591e1b2007-09-13 23:52:58 +0000524 for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
Chris Lattner06611052007-08-28 05:03:08 +0000525 BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D);
526 if (BVD && !BVD->hasLocalStorage())
527 BVD = 0;
528 if (BVD == 0)
Steve Naroffcb597472007-09-13 21:41:19 +0000529 Diag(dyn_cast<ScopedDecl>(D)->getLocation(),
530 diag::err_non_variable_decl_in_for);
Chris Lattner06611052007-08-28 05:03:08 +0000531 // FIXME: mark decl erroneous!
532 }
Chris Lattner4b009652007-07-25 00:24:17 +0000533 }
534 if (Second) {
Chris Lattner3332fbd2007-08-28 04:55:47 +0000535 DefaultFunctionArrayConversion(Second);
536 QualType SecondType = Second->getType();
Chris Lattner4b009652007-07-25 00:24:17 +0000537
Chris Lattner3332fbd2007-08-28 04:55:47 +0000538 if (!SecondType->isScalarType()) // C99 6.8.5p2
Chris Lattner4b009652007-07-25 00:24:17 +0000539 return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar,
Chris Lattner3332fbd2007-08-28 04:55:47 +0000540 SecondType.getAsString(), Second->getSourceRange());
Chris Lattner4b009652007-07-25 00:24:17 +0000541 }
Steve Naroff5d2fff82007-08-31 23:28:33 +0000542 return new ForStmt(First, Second, Third, Body, ForLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000543}
544
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000545Action::StmtResult
Fariborz Jahaniandf2b0952008-01-10 00:24:29 +0000546Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000547 SourceLocation LParenLoc,
548 StmtTy *first, ExprTy *second,
549 SourceLocation RParenLoc, StmtTy *body) {
550 Stmt *First = static_cast<Stmt*>(first);
551 Expr *Second = static_cast<Expr*>(second);
552 Stmt *Body = static_cast<Stmt*>(body);
Fariborz Jahanian6833b3b2008-01-10 20:33:58 +0000553 if (First) {
554 QualType FirstType;
555 if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) {
556 FirstType = cast<ValueDecl>(DS->getDecl())->getType();
557 // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
558 // identifiers for objects having storage class 'auto' or 'register'.
559 ScopedDecl *D = DS->getDecl();
560 BlockVarDecl *BVD = cast<BlockVarDecl>(D);
561 if (!BVD->hasLocalStorage())
562 return Diag(BVD->getLocation(), diag::err_non_variable_decl_in_for);
563 if (D->getNextDeclarator())
564 return Diag(D->getLocation(), diag::err_toomany_element_decls);
565 }
566 else
567 FirstType = static_cast<Expr*>(first)->getType();
568 if (!isObjCObjectPointerType(FirstType))
569 Diag(ForLoc, diag::err_selector_element_type,
570 FirstType.getAsString(), First->getSourceRange());
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000571 }
572 if (Second) {
573 DefaultFunctionArrayConversion(Second);
574 QualType SecondType = Second->getType();
Ted Kremenek42730c52008-01-07 19:49:32 +0000575 if (!isObjCObjectPointerType(SecondType))
Fariborz Jahaniandf2b0952008-01-10 00:24:29 +0000576 Diag(ForLoc, diag::err_collection_expr_type,
Fariborz Jahanianfe0982d2008-01-04 00:27:46 +0000577 SecondType.getAsString(), Second->getSourceRange());
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000578 }
Fariborz Jahaniandf2b0952008-01-10 00:24:29 +0000579 return new ObjCForCollectionStmt(First, Second, Body, ForLoc, RParenLoc);
Fariborz Jahanian1300bc72008-01-03 17:55:25 +0000580}
Chris Lattner4b009652007-07-25 00:24:17 +0000581
582Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000583Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000584 IdentifierInfo *LabelII) {
585 // Look up the record for this label identifier.
586 LabelStmt *&LabelDecl = LabelMap[LabelII];
587
588 // If we haven't seen this label yet, create a forward reference.
589 if (LabelDecl == 0)
590 LabelDecl = new LabelStmt(LabelLoc, LabelII, 0);
591
Ted Kremeneka65ad462007-09-06 17:11:52 +0000592 return new GotoStmt(LabelDecl, GotoLoc, LabelLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000593}
594
595Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000596Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
Chris Lattner4b009652007-07-25 00:24:17 +0000597 ExprTy *DestExp) {
598 // FIXME: Verify that the operand is convertible to void*.
599
600 return new IndirectGotoStmt((Expr*)DestExp);
601}
602
603Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000604Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) {
Chris Lattner4b009652007-07-25 00:24:17 +0000605 Scope *S = CurScope->getContinueParent();
606 if (!S) {
607 // C99 6.8.6.2p1: A break shall appear only in or as a loop body.
608 Diag(ContinueLoc, diag::err_continue_not_in_loop);
609 return true;
610 }
611
Steve Naroffc32a20d2007-08-31 23:49:30 +0000612 return new ContinueStmt(ContinueLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000613}
614
615Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000616Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) {
Chris Lattner4b009652007-07-25 00:24:17 +0000617 Scope *S = CurScope->getBreakParent();
618 if (!S) {
619 // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body.
620 Diag(BreakLoc, diag::err_break_not_in_loop_or_switch);
621 return true;
622 }
623
Steve Naroffc32a20d2007-08-31 23:49:30 +0000624 return new BreakStmt(BreakLoc);
Chris Lattner4b009652007-07-25 00:24:17 +0000625}
626
627
628Action::StmtResult
Steve Naroff5cbb02f2007-09-16 14:56:35 +0000629Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
Chris Lattner4b009652007-07-25 00:24:17 +0000630 Expr *RetValExp = static_cast<Expr *>(rex);
Chris Lattner005ed752008-01-04 18:04:52 +0000631 QualType FnRetType = CurFunctionDecl ? CurFunctionDecl->getResultType() :
632 CurMethodDecl->getResultType();
Chris Lattner4b009652007-07-25 00:24:17 +0000633
Chris Lattner005ed752008-01-04 18:04:52 +0000634 if (FnRetType->isVoidType()) {
Chris Lattner4b009652007-07-25 00:24:17 +0000635 if (RetValExp) // C99 6.8.6.4p1 (ext_ since GCC warns)
Fariborz Jahanian336b2e82007-12-04 19:20:11 +0000636 Diag(ReturnLoc, diag::ext_return_has_expr,
637 (CurFunctionDecl ? CurFunctionDecl->getIdentifier()->getName() :
638 CurMethodDecl->getSelector().getName()),
Chris Lattner4b009652007-07-25 00:24:17 +0000639 RetValExp->getSourceRange());
Steve Naroffc32a20d2007-08-31 23:49:30 +0000640 return new ReturnStmt(ReturnLoc, RetValExp);
Chris Lattner4b009652007-07-25 00:24:17 +0000641 } else {
642 if (!RetValExp) {
Fariborz Jahanian336b2e82007-12-04 19:20:11 +0000643 const char *funcName = CurFunctionDecl ?
644 CurFunctionDecl->getIdentifier()->getName() :
645 CurMethodDecl->getSelector().getName().c_str();
Chris Lattner4b009652007-07-25 00:24:17 +0000646 if (getLangOptions().C99) // C99 6.8.6.4p1 (ext_ since GCC warns)
647 Diag(ReturnLoc, diag::ext_return_missing_expr, funcName);
648 else // C90 6.6.6.4p4
649 Diag(ReturnLoc, diag::warn_return_missing_expr, funcName);
Steve Naroffc32a20d2007-08-31 23:49:30 +0000650 return new ReturnStmt(ReturnLoc, (Expr*)0);
Chris Lattner4b009652007-07-25 00:24:17 +0000651 }
652 }
653 // we have a non-void function with an expression, continue checking
Chris Lattner005ed752008-01-04 18:04:52 +0000654 QualType RetValType = RetValExp->getType();
Chris Lattner4b009652007-07-25 00:24:17 +0000655
656 // C99 6.8.6.4p3(136): The return statement is not an assignment. The
657 // overlap restriction of subclause 6.5.16.1 does not apply to the case of
658 // function return.
Chris Lattner005ed752008-01-04 18:04:52 +0000659 AssignConvertType ConvTy = CheckSingleAssignmentConstraints(FnRetType,
660 RetValExp);
661 if (DiagnoseAssignmentResult(ConvTy, ReturnLoc, FnRetType,
662 RetValType, RetValExp, "returning"))
663 return true;
Ted Kremenek45925ab2007-08-17 16:46:58 +0000664
Chris Lattner005ed752008-01-04 18:04:52 +0000665 if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc);
Ted Kremenek45925ab2007-08-17 16:46:58 +0000666
Steve Naroffc32a20d2007-08-31 23:49:30 +0000667 return new ReturnStmt(ReturnLoc, (Expr*)RetValExp);
Chris Lattner4b009652007-07-25 00:24:17 +0000668}
669
Anders Carlsson076c1112007-11-20 19:21:03 +0000670Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
Anders Carlsson759f45d2007-11-23 23:12:25 +0000671 bool IsVolatile,
Anders Carlsson965d5202007-11-22 01:36:19 +0000672 unsigned NumOutputs,
673 unsigned NumInputs,
674 std::string *Names,
675 ExprTy **Constraints,
676 ExprTy **Exprs,
Anders Carlsson076c1112007-11-20 19:21:03 +0000677 ExprTy *AsmString,
Anders Carlsson965d5202007-11-22 01:36:19 +0000678 unsigned NumClobbers,
679 ExprTy **Clobbers,
Chris Lattner8a40a832007-10-29 04:04:16 +0000680 SourceLocation RParenLoc) {
Anders Carlsson076c1112007-11-20 19:21:03 +0000681 Expr *E = (Expr *)AsmString;
Anders Carlsson759f45d2007-11-23 23:12:25 +0000682
Anders Carlssonb4487a82007-11-23 19:43:50 +0000683 for (unsigned i = 0; i < NumOutputs; i++) {
Anders Carlsson4ce42302007-11-27 04:11:28 +0000684 StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]);
685 assert(!Literal->isWide() &&
686 "Output constraint strings should not be wide!");
687
688 std::string OutputConstraint(Literal->getStrData(),
689 Literal->getByteLength());
690
691 TargetInfo::ConstraintInfo info;
692 if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),
693 info)) {
694 // FIXME: We currently leak memory here.
695 Diag(Literal->getLocStart(),
696 diag::err_invalid_output_constraint_in_asm);
697 return true;
698 }
699
700 // Check that the output exprs are valid lvalues.
Anders Carlssonb4487a82007-11-23 19:43:50 +0000701 Expr *OutputExpr = (Expr *)Exprs[i];
702 Expr::isLvalueResult Result = OutputExpr->isLvalue();
Anders Carlssonb4487a82007-11-23 19:43:50 +0000703 if (Result != Expr::LV_Valid) {
704 ParenExpr *PE = cast<ParenExpr>(OutputExpr);
705
706 Diag(PE->getSubExpr()->getLocStart(),
707 diag::err_invalid_lvalue_in_asm_output,
708 PE->getSubExpr()->getSourceRange());
709
710 // FIXME: We currently leak memory here.
711 return true;
712 }
713 }
714
Anders Carlssonb4487a82007-11-23 19:43:50 +0000715 for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
Anders Carlsson4ce42302007-11-27 04:11:28 +0000716 StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]);
717 assert(!Literal->isWide() &&
718 "Output constraint strings should not be wide!");
Anders Carlssonb4487a82007-11-23 19:43:50 +0000719
Anders Carlsson4ce42302007-11-27 04:11:28 +0000720 std::string InputConstraint(Literal->getStrData(),
721 Literal->getByteLength());
722
723 TargetInfo::ConstraintInfo info;
724 if (!Context.Target.validateInputConstraint(InputConstraint.c_str(),
725 NumOutputs,
726 info)) {
727 // FIXME: We currently leak memory here.
728 Diag(Literal->getLocStart(),
729 diag::err_invalid_input_constraint_in_asm);
730 return true;
731 }
732
733 // Check that the input exprs aren't of type void.
734 Expr *InputExpr = (Expr *)Exprs[i];
Anders Carlssonb4487a82007-11-23 19:43:50 +0000735 if (InputExpr->getType()->isVoidType()) {
736 ParenExpr *PE = cast<ParenExpr>(InputExpr);
737
738 Diag(PE->getSubExpr()->getLocStart(),
739 diag::err_invalid_type_in_asm_input,
740 PE->getType().getAsString(),
741 PE->getSubExpr()->getSourceRange());
742
743 // FIXME: We currently leak memory here.
744 return true;
745 }
746 }
Anders Carlsson965d5202007-11-22 01:36:19 +0000747
Anders Carlsson49dadd62007-11-25 00:25:21 +0000748 // Check that the clobbers are valid.
749 for (unsigned i = 0; i < NumClobbers; i++) {
750 StringLiteral *Literal = cast<StringLiteral>((Expr *)Clobbers[i]);
751 assert(!Literal->isWide() && "Clobber strings should not be wide!");
752
753 llvm::SmallString<16> Clobber(Literal->getStrData(),
754 Literal->getStrData() +
755 Literal->getByteLength());
756
757 if (!Context.Target.isValidGCCRegisterName(Clobber.c_str())) {
758 Diag(Literal->getLocStart(),
759 diag::err_unknown_register_name_in_asm,
760 Clobber.c_str());
761
762 // FIXME: We currently leak memory here.
763 return true;
764 }
765 }
766
Anders Carlsson965d5202007-11-22 01:36:19 +0000767 return new AsmStmt(AsmLoc,
Anders Carlsson759f45d2007-11-23 23:12:25 +0000768 IsVolatile,
Anders Carlsson965d5202007-11-22 01:36:19 +0000769 NumOutputs,
770 NumInputs,
771 Names,
772 reinterpret_cast<StringLiteral**>(Constraints),
773 reinterpret_cast<Expr**>(Exprs),
774 cast<StringLiteral>(E),
775 NumClobbers,
776 reinterpret_cast<StringLiteral**>(Clobbers),
777 RParenLoc);
Chris Lattner8a40a832007-10-29 04:04:16 +0000778}
Fariborz Jahanian06798362007-11-01 23:59:59 +0000779
780Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000781Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc,
Fariborz Jahanian06798362007-11-01 23:59:59 +0000782 SourceLocation RParen, StmtTy *Parm,
783 StmtTy *Body, StmtTy *CatchList) {
Ted Kremenek42730c52008-01-07 19:49:32 +0000784 ObjCAtCatchStmt *CS = new ObjCAtCatchStmt(AtLoc, RParen,
Fariborz Jahanian06798362007-11-01 23:59:59 +0000785 static_cast<Stmt*>(Parm), static_cast<Stmt*>(Body),
786 static_cast<Stmt*>(CatchList));
787 return CatchList ? CatchList : CS;
788}
789
Fariborz Jahaniande3abf82007-11-02 00:18:53 +0000790Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000791Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, StmtTy *Body) {
792 ObjCAtFinallyStmt *FS = new ObjCAtFinallyStmt(AtLoc,
Fariborz Jahaniande3abf82007-11-02 00:18:53 +0000793 static_cast<Stmt*>(Body));
794 return FS;
795}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000796
797Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000798Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc,
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000799 StmtTy *Try, StmtTy *Catch, StmtTy *Finally) {
Ted Kremenek42730c52008-01-07 19:49:32 +0000800 ObjCAtTryStmt *TS = new ObjCAtTryStmt(AtLoc, static_cast<Stmt*>(Try),
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000801 static_cast<Stmt*>(Catch),
802 static_cast<Stmt*>(Finally));
803 return TS;
804}
805
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000806Action::StmtResult
Ted Kremenek42730c52008-01-07 19:49:32 +0000807Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw) {
808 ObjCAtThrowStmt *TS = new ObjCAtThrowStmt(AtLoc, static_cast<Stmt*>(Throw));
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000809 return TS;
810}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000811
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000812Action::StmtResult
813Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprTy *SynchExpr,
814 StmtTy *SynchBody) {
815 ObjCAtSynchronizedStmt *SS = new ObjCAtSynchronizedStmt(AtLoc,
816 static_cast<Expr*>(SynchExpr), static_cast<Stmt*>(SynchBody));
817 return SS;
818}
Fariborz Jahanianb8bf6072007-11-02 15:39:31 +0000819
820