Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for statements. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Sema.h" |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | c4a1dea | 2008-08-11 05:35:13 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclObjC.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 18 | #include "clang/Basic/TargetInfo.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | #include "clang/Basic/Diagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 22 | Sema::StmtResult Sema::ActOnExprStmt(ExprTy *expr) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 23 | Expr *E = static_cast<Expr*>(expr); |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 24 | assert(E && "ActOnExprStmt(): missing expression"); |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 25 | |
| 26 | // C99 6.8.3p2: The expression in an expression statement is evaluated as a |
| 27 | // void expression for its side effects. Conversion to void allows any |
| 28 | // operand, even incomplete types. |
| 29 | |
| 30 | // Same thing in for stmt first clause (when expr) and third clause. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | return E; |
| 32 | } |
| 33 | |
| 34 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 35 | Sema::StmtResult Sema::ActOnNullStmt(SourceLocation SemiLoc) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 36 | return new NullStmt(SemiLoc); |
| 37 | } |
| 38 | |
Chris Lattner | 81c018d | 2008-03-13 06:29:04 +0000 | [diff] [blame] | 39 | Sema::StmtResult Sema::ActOnDeclStmt(DeclTy *decl, SourceLocation StartLoc, |
| 40 | SourceLocation EndLoc) { |
| 41 | if (decl == 0) |
| 42 | return true; |
| 43 | |
| 44 | ScopedDecl *SD = cast<ScopedDecl>(static_cast<Decl *>(decl)); |
| 45 | return new DeclStmt(SD, StartLoc, EndLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 49 | Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
Chris Lattner | 98414c1 | 2007-08-31 21:49:55 +0000 | [diff] [blame] | 50 | StmtTy **elts, unsigned NumElts, bool isStmtExpr) { |
Chris Lattner | c30ebfb | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 51 | Stmt **Elts = reinterpret_cast<Stmt**>(elts); |
| 52 | // If we're in C89 mode, check that we don't have any decls after stmts. If |
| 53 | // so, emit an extension diagnostic. |
| 54 | if (!getLangOptions().C99 && !getLangOptions().CPlusPlus) { |
| 55 | // Note that __extension__ can be around a decl. |
| 56 | unsigned i = 0; |
| 57 | // Skip over all declarations. |
| 58 | for (; i != NumElts && isa<DeclStmt>(Elts[i]); ++i) |
| 59 | /*empty*/; |
| 60 | |
| 61 | // We found the end of the list or a statement. Scan for another declstmt. |
| 62 | for (; i != NumElts && !isa<DeclStmt>(Elts[i]); ++i) |
| 63 | /*empty*/; |
| 64 | |
| 65 | if (i != NumElts) { |
Steve Naroff | 8e74c93 | 2007-09-13 21:41:19 +0000 | [diff] [blame] | 66 | ScopedDecl *D = cast<DeclStmt>(Elts[i])->getDecl(); |
Chris Lattner | c30ebfb | 2007-08-27 04:29:41 +0000 | [diff] [blame] | 67 | Diag(D->getLocation(), diag::ext_mixed_decls_code); |
| 68 | } |
| 69 | } |
Chris Lattner | 98414c1 | 2007-08-31 21:49:55 +0000 | [diff] [blame] | 70 | // Warn about unused expressions in statements. |
| 71 | for (unsigned i = 0; i != NumElts; ++i) { |
| 72 | Expr *E = dyn_cast<Expr>(Elts[i]); |
| 73 | if (!E) continue; |
| 74 | |
| 75 | // Warn about expressions with unused results. |
| 76 | if (E->hasLocalSideEffect() || E->getType()->isVoidType()) |
| 77 | continue; |
| 78 | |
| 79 | // The last expr in a stmt expr really is used. |
| 80 | if (isStmtExpr && i == NumElts-1) |
| 81 | continue; |
| 82 | |
| 83 | /// DiagnoseDeadExpr - This expression is side-effect free and evaluated in |
| 84 | /// a context where the result is unused. Emit a diagnostic to warn about |
| 85 | /// this. |
| 86 | if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) |
| 87 | Diag(BO->getOperatorLoc(), diag::warn_unused_expr, |
| 88 | BO->getLHS()->getSourceRange(), BO->getRHS()->getSourceRange()); |
| 89 | else if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) |
| 90 | Diag(UO->getOperatorLoc(), diag::warn_unused_expr, |
| 91 | UO->getSubExpr()->getSourceRange()); |
| 92 | else |
| 93 | Diag(E->getExprLoc(), diag::warn_unused_expr, E->getSourceRange()); |
| 94 | } |
| 95 | |
Steve Naroff | b5a6958 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 96 | return new CompoundStmt(Elts, NumElts, L, R); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 100 | Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval, |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 101 | SourceLocation DotDotDotLoc, ExprTy *rhsval, |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 102 | SourceLocation ColonLoc, StmtTy *subStmt) { |
| 103 | Stmt *SubStmt = static_cast<Stmt*>(subStmt); |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 104 | Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 105 | assert((LHSVal != 0) && "missing expression in case statement"); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 106 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 107 | SourceLocation ExpLoc; |
| 108 | // C99 6.8.4.2p3: The expression shall be an integer constant. |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 109 | if (!LHSVal->isIntegerConstantExpr(Context, &ExpLoc)) { |
| 110 | Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr, |
| 111 | LHSVal->getSourceRange()); |
| 112 | return SubStmt; |
| 113 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 114 | |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 115 | // GCC extension: The expression shall be an integer constant. |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 116 | if (RHSVal && !RHSVal->isIntegerConstantExpr(Context, &ExpLoc)) { |
| 117 | Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr, |
| 118 | RHSVal->getSourceRange()); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 119 | RHSVal = 0; // Recover by just forgetting about it. |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 120 | } |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 121 | |
| 122 | if (SwitchStack.empty()) { |
| 123 | Diag(CaseLoc, diag::err_case_not_in_switch); |
| 124 | return SubStmt; |
| 125 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 126 | |
Steve Naroff | b5a6958 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 127 | CaseStmt *CS = new CaseStmt(LHSVal, RHSVal, SubStmt, CaseLoc); |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 128 | SwitchStack.back()->addSwitchCase(CS); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 129 | return CS; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 133 | Sema::ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 134 | StmtTy *subStmt, Scope *CurScope) { |
| 135 | Stmt *SubStmt = static_cast<Stmt*>(subStmt); |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 137 | if (SwitchStack.empty()) { |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 138 | Diag(DefaultLoc, diag::err_default_not_in_switch); |
| 139 | return SubStmt; |
| 140 | } |
| 141 | |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 142 | DefaultStmt *DS = new DefaultStmt(DefaultLoc, SubStmt); |
Chris Lattner | 8a87e57 | 2007-07-23 17:05:23 +0000 | [diff] [blame] | 143 | SwitchStack.back()->addSwitchCase(DS); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 145 | return DS; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 149 | Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 150 | SourceLocation ColonLoc, StmtTy *subStmt) { |
| 151 | Stmt *SubStmt = static_cast<Stmt*>(subStmt); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 152 | // Look up the record for this label identifier. |
| 153 | LabelStmt *&LabelDecl = LabelMap[II]; |
| 154 | |
| 155 | // If not forward referenced or defined already, just create a new LabelStmt. |
| 156 | if (LabelDecl == 0) |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 157 | return LabelDecl = new LabelStmt(IdentLoc, II, SubStmt); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 158 | |
| 159 | assert(LabelDecl->getID() == II && "Label mismatch!"); |
| 160 | |
| 161 | // Otherwise, this label was either forward reference or multiply defined. If |
| 162 | // multiply defined, reject it now. |
| 163 | if (LabelDecl->getSubStmt()) { |
| 164 | Diag(IdentLoc, diag::err_redefinition_of_label, LabelDecl->getName()); |
| 165 | Diag(LabelDecl->getIdentLoc(), diag::err_previous_definition); |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 166 | return SubStmt; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | // Otherwise, this label was forward declared, and we just found its real |
| 170 | // definition. Fill in the forward definition and return it. |
| 171 | LabelDecl->setIdentLoc(IdentLoc); |
Chris Lattner | 0fa152e | 2007-07-21 03:00:26 +0000 | [diff] [blame] | 172 | LabelDecl->setSubStmt(SubStmt); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 173 | return LabelDecl; |
| 174 | } |
| 175 | |
| 176 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 177 | Sema::ActOnIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 178 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 179 | StmtTy *ElseVal) { |
| 180 | Expr *condExpr = (Expr *)CondVal; |
Anders Carlsson | 2d85f8b | 2007-10-10 20:50:11 +0000 | [diff] [blame] | 181 | Stmt *thenStmt = (Stmt *)ThenVal; |
| 182 | |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 183 | assert(condExpr && "ActOnIfStmt(): missing expression"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 184 | |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 185 | DefaultFunctionArrayConversion(condExpr); |
| 186 | QualType condType = condExpr->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 187 | |
| 188 | if (!condType->isScalarType()) // C99 6.8.4.1p1 |
| 189 | return Diag(IfLoc, diag::err_typecheck_statement_requires_scalar, |
| 190 | condType.getAsString(), condExpr->getSourceRange()); |
| 191 | |
Anders Carlsson | 2d85f8b | 2007-10-10 20:50:11 +0000 | [diff] [blame] | 192 | // Warn if the if block has a null body without an else value. |
| 193 | // this helps prevent bugs due to typos, such as |
| 194 | // if (condition); |
| 195 | // do_stuff(); |
| 196 | if (!ElseVal) { |
| 197 | if (NullStmt* stmt = dyn_cast<NullStmt>(thenStmt)) |
| 198 | Diag(stmt->getSemiLoc(), diag::warn_empty_if_body); |
| 199 | } |
| 200 | |
| 201 | return new IfStmt(IfLoc, condExpr, thenStmt, (Stmt*)ElseVal); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 205 | Sema::ActOnStartOfSwitchStmt(ExprTy *cond) { |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 206 | Expr *Cond = static_cast<Expr*>(cond); |
| 207 | |
| 208 | // C99 6.8.4.2p5 - Integer promotions are performed on the controlling expr. |
| 209 | UsualUnaryConversions(Cond); |
| 210 | |
| 211 | SwitchStmt *SS = new SwitchStmt(Cond); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 212 | SwitchStack.push_back(SS); |
| 213 | return SS; |
| 214 | } |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 215 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 216 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 217 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 218 | /// the specified diagnostic. |
| 219 | void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val, |
| 220 | unsigned NewWidth, bool NewSign, |
| 221 | SourceLocation Loc, |
| 222 | unsigned DiagID) { |
| 223 | // Perform a conversion to the promoted condition type if needed. |
| 224 | if (NewWidth > Val.getBitWidth()) { |
| 225 | // If this is an extension, just do it. |
| 226 | llvm::APSInt OldVal(Val); |
| 227 | Val.extend(NewWidth); |
| 228 | |
| 229 | // If the input was signed and negative and the output is unsigned, |
| 230 | // warn. |
| 231 | if (!NewSign && OldVal.isSigned() && OldVal.isNegative()) |
| 232 | Diag(Loc, DiagID, OldVal.toString(), Val.toString()); |
| 233 | |
| 234 | Val.setIsSigned(NewSign); |
| 235 | } else if (NewWidth < Val.getBitWidth()) { |
| 236 | // If this is a truncation, check for overflow. |
| 237 | llvm::APSInt ConvVal(Val); |
| 238 | ConvVal.trunc(NewWidth); |
Chris Lattner | b2137ae | 2007-08-23 22:08:35 +0000 | [diff] [blame] | 239 | ConvVal.setIsSigned(NewSign); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 240 | ConvVal.extend(Val.getBitWidth()); |
Chris Lattner | b2137ae | 2007-08-23 22:08:35 +0000 | [diff] [blame] | 241 | ConvVal.setIsSigned(Val.isSigned()); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 242 | if (ConvVal != Val) |
| 243 | Diag(Loc, DiagID, Val.toString(), ConvVal.toString()); |
| 244 | |
| 245 | // Regardless of whether a diagnostic was emitted, really do the |
| 246 | // truncation. |
| 247 | Val.trunc(NewWidth); |
Chris Lattner | b2137ae | 2007-08-23 22:08:35 +0000 | [diff] [blame] | 248 | Val.setIsSigned(NewSign); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 249 | } else if (NewSign != Val.isSigned()) { |
| 250 | // Convert the sign to match the sign of the condition. This can cause |
| 251 | // overflow as well: unsigned(INTMIN) |
| 252 | llvm::APSInt OldVal(Val); |
| 253 | Val.setIsSigned(NewSign); |
| 254 | |
| 255 | if (Val.isNegative()) // Sign bit changes meaning. |
| 256 | Diag(Loc, DiagID, OldVal.toString(), Val.toString()); |
| 257 | } |
| 258 | } |
| 259 | |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 260 | namespace { |
| 261 | struct CaseCompareFunctor { |
| 262 | bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS, |
| 263 | const llvm::APSInt &RHS) { |
| 264 | return LHS.first < RHS; |
| 265 | } |
Chris Lattner | 0e85a27 | 2007-09-03 18:31:57 +0000 | [diff] [blame] | 266 | bool operator()(const std::pair<llvm::APSInt, CaseStmt*> &LHS, |
| 267 | const std::pair<llvm::APSInt, CaseStmt*> &RHS) { |
| 268 | return LHS.first < RHS.first; |
| 269 | } |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 270 | bool operator()(const llvm::APSInt &LHS, |
| 271 | const std::pair<llvm::APSInt, CaseStmt*> &RHS) { |
| 272 | return LHS < RHS.first; |
| 273 | } |
| 274 | }; |
| 275 | } |
| 276 | |
Chris Lattner | 764a7ce | 2007-09-21 18:15:22 +0000 | [diff] [blame] | 277 | /// CmpCaseVals - Comparison predicate for sorting case values. |
| 278 | /// |
| 279 | static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs, |
| 280 | const std::pair<llvm::APSInt, CaseStmt*>& rhs) { |
| 281 | if (lhs.first < rhs.first) |
| 282 | return true; |
| 283 | |
| 284 | if (lhs.first == rhs.first && |
| 285 | lhs.second->getCaseLoc().getRawEncoding() |
| 286 | < rhs.second->getCaseLoc().getRawEncoding()) |
| 287 | return true; |
| 288 | return false; |
| 289 | } |
| 290 | |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 291 | Action::StmtResult |
Chris Lattner | 764a7ce | 2007-09-21 18:15:22 +0000 | [diff] [blame] | 292 | Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, |
| 293 | ExprTy *Body) { |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 294 | Stmt *BodyStmt = (Stmt*)Body; |
| 295 | |
| 296 | SwitchStmt *SS = SwitchStack.back(); |
| 297 | assert(SS == (SwitchStmt*)Switch && "switch stack missing push/pop!"); |
| 298 | |
Steve Naroff | 9dcbfa4 | 2007-09-01 21:08:38 +0000 | [diff] [blame] | 299 | SS->setBody(BodyStmt, SwitchLoc); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 300 | SwitchStack.pop_back(); |
| 301 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 302 | Expr *CondExpr = SS->getCond(); |
| 303 | QualType CondType = CondExpr->getType(); |
Chris Lattner | 6c36be5 | 2007-07-18 02:28:47 +0000 | [diff] [blame] | 304 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 305 | if (!CondType->isIntegerType()) { // C99 6.8.4.2p1 |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 306 | Diag(SwitchLoc, diag::err_typecheck_statement_requires_integer, |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 307 | CondType.getAsString(), CondExpr->getSourceRange()); |
| 308 | return true; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 309 | } |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 310 | |
| 311 | // Get the bitwidth of the switched-on value before promotions. We must |
| 312 | // convert the integer case values to this width before comparison. |
Chris Lattner | 98be494 | 2008-03-05 18:54:05 +0000 | [diff] [blame] | 313 | unsigned CondWidth = static_cast<unsigned>(Context.getTypeSize(CondType)); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 314 | bool CondIsSigned = CondType->isSignedIntegerType(); |
| 315 | |
| 316 | // Accumulate all of the case values in a vector so that we can sort them |
| 317 | // and detect duplicates. This vector contains the APInt for the case after |
| 318 | // it has been converted to the condition type. |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 319 | typedef llvm::SmallVector<std::pair<llvm::APSInt, CaseStmt*>, 64> CaseValsTy; |
| 320 | CaseValsTy CaseVals; |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 321 | |
| 322 | // Keep track of any GNU case ranges we see. The APSInt is the low value. |
| 323 | std::vector<std::pair<llvm::APSInt, CaseStmt*> > CaseRanges; |
| 324 | |
| 325 | DefaultStmt *TheDefaultStmt = 0; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 326 | |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 327 | bool CaseListIsErroneous = false; |
| 328 | |
| 329 | for (SwitchCase *SC = SS->getSwitchCaseList(); SC; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 330 | SC = SC->getNextSwitchCase()) { |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 331 | |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 332 | if (DefaultStmt *DS = dyn_cast<DefaultStmt>(SC)) { |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 333 | if (TheDefaultStmt) { |
| 334 | Diag(DS->getDefaultLoc(), diag::err_multiple_default_labels_defined); |
| 335 | Diag(TheDefaultStmt->getDefaultLoc(), diag::err_first_label); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 336 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 337 | // FIXME: Remove the default statement from the switch block so that |
| 338 | // we'll return a valid AST. This requires recursing down the |
| 339 | // AST and finding it, not something we are set up to do right now. For |
| 340 | // now, just lop the entire switch stmt out of the AST. |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 341 | CaseListIsErroneous = true; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 342 | } |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 343 | TheDefaultStmt = DS; |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 344 | |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 345 | } else { |
| 346 | CaseStmt *CS = cast<CaseStmt>(SC); |
| 347 | |
| 348 | // We already verified that the expression has a i-c-e value (C99 |
| 349 | // 6.8.4.2p3) - get that value now. |
| 350 | llvm::APSInt LoVal(32); |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 351 | Expr *Lo = CS->getLHS(); |
| 352 | Lo->isIntegerConstantExpr(LoVal, Context); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 353 | |
| 354 | // Convert the value to the same width/sign as the condition. |
| 355 | ConvertIntegerToTypeWarnOnOverflow(LoVal, CondWidth, CondIsSigned, |
| 356 | CS->getLHS()->getLocStart(), |
| 357 | diag::warn_case_value_overflow); |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 358 | |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 359 | // If the LHS is not the same type as the condition, insert an implicit |
| 360 | // cast. |
| 361 | ImpCastExprToType(Lo, CondType); |
| 362 | CS->setLHS(Lo); |
| 363 | |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 364 | // If this is a case range, remember it in CaseRanges, otherwise CaseVals. |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 365 | if (CS->getRHS()) |
| 366 | CaseRanges.push_back(std::make_pair(LoVal, CS)); |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 367 | else |
| 368 | CaseVals.push_back(std::make_pair(LoVal, CS)); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 372 | // Sort all the scalar case values so we can easily detect duplicates. |
Chris Lattner | 764a7ce | 2007-09-21 18:15:22 +0000 | [diff] [blame] | 373 | std::stable_sort(CaseVals.begin(), CaseVals.end(), CmpCaseVals); |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 374 | |
Chris Lattner | f334850 | 2007-08-23 14:29:07 +0000 | [diff] [blame] | 375 | if (!CaseVals.empty()) { |
| 376 | for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) { |
| 377 | if (CaseVals[i].first == CaseVals[i+1].first) { |
| 378 | // If we have a duplicate, report it. |
| 379 | Diag(CaseVals[i+1].second->getLHS()->getLocStart(), |
| 380 | diag::err_duplicate_case, CaseVals[i].first.toString()); |
| 381 | Diag(CaseVals[i].second->getLHS()->getLocStart(), |
| 382 | diag::err_duplicate_case_prev); |
| 383 | // FIXME: We really want to remove the bogus case stmt from the substmt, |
| 384 | // but we have no way to do this right now. |
| 385 | CaseListIsErroneous = true; |
| 386 | } |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 389 | |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 390 | // Detect duplicate case ranges, which usually don't exist at all in the first |
| 391 | // place. |
| 392 | if (!CaseRanges.empty()) { |
| 393 | // Sort all the case ranges by their low value so we can easily detect |
| 394 | // overlaps between ranges. |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 395 | std::stable_sort(CaseRanges.begin(), CaseRanges.end()); |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 396 | |
| 397 | // Scan the ranges, computing the high values and removing empty ranges. |
| 398 | std::vector<llvm::APSInt> HiVals; |
Chris Lattner | 6efc4d3 | 2007-08-23 17:48:14 +0000 | [diff] [blame] | 399 | for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) { |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 400 | CaseStmt *CR = CaseRanges[i].second; |
| 401 | llvm::APSInt HiVal(32); |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 402 | Expr *Hi = CR->getRHS(); |
| 403 | Hi->isIntegerConstantExpr(HiVal, Context); |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 404 | |
| 405 | // Convert the value to the same width/sign as the condition. |
| 406 | ConvertIntegerToTypeWarnOnOverflow(HiVal, CondWidth, CondIsSigned, |
| 407 | CR->getRHS()->getLocStart(), |
| 408 | diag::warn_case_value_overflow); |
| 409 | |
Chris Lattner | 1e0a390 | 2008-01-16 19:17:22 +0000 | [diff] [blame] | 410 | // If the LHS is not the same type as the condition, insert an implicit |
| 411 | // cast. |
| 412 | ImpCastExprToType(Hi, CondType); |
| 413 | CR->setRHS(Hi); |
| 414 | |
Chris Lattner | 6efc4d3 | 2007-08-23 17:48:14 +0000 | [diff] [blame] | 415 | // If the low value is bigger than the high value, the case is empty. |
| 416 | if (CaseRanges[i].first > HiVal) { |
| 417 | Diag(CR->getLHS()->getLocStart(), diag::warn_case_empty_range, |
| 418 | SourceRange(CR->getLHS()->getLocStart(), |
| 419 | CR->getRHS()->getLocEnd())); |
| 420 | CaseRanges.erase(CaseRanges.begin()+i); |
| 421 | --i, --e; |
| 422 | continue; |
| 423 | } |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 424 | HiVals.push_back(HiVal); |
| 425 | } |
| 426 | |
| 427 | // Rescan the ranges, looking for overlap with singleton values and other |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 428 | // ranges. Since the range list is sorted, we only need to compare case |
| 429 | // ranges with their neighbors. |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 430 | for (unsigned i = 0, e = CaseRanges.size(); i != e; ++i) { |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 431 | llvm::APSInt &CRLo = CaseRanges[i].first; |
| 432 | llvm::APSInt &CRHi = HiVals[i]; |
| 433 | CaseStmt *CR = CaseRanges[i].second; |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 434 | |
Chris Lattner | 0471f5b | 2007-08-23 18:29:20 +0000 | [diff] [blame] | 435 | // Check to see whether the case range overlaps with any singleton cases. |
| 436 | CaseStmt *OverlapStmt = 0; |
| 437 | llvm::APSInt OverlapVal(32); |
| 438 | |
| 439 | // Find the smallest value >= the lower bound. If I is in the case range, |
| 440 | // then we have overlap. |
| 441 | CaseValsTy::iterator I = std::lower_bound(CaseVals.begin(), |
| 442 | CaseVals.end(), CRLo, |
| 443 | CaseCompareFunctor()); |
| 444 | if (I != CaseVals.end() && I->first < CRHi) { |
| 445 | OverlapVal = I->first; // Found overlap with scalar. |
| 446 | OverlapStmt = I->second; |
| 447 | } |
| 448 | |
| 449 | // Find the smallest value bigger than the upper bound. |
| 450 | I = std::upper_bound(I, CaseVals.end(), CRHi, CaseCompareFunctor()); |
| 451 | if (I != CaseVals.begin() && (I-1)->first >= CRLo) { |
| 452 | OverlapVal = (I-1)->first; // Found overlap with scalar. |
| 453 | OverlapStmt = (I-1)->second; |
| 454 | } |
| 455 | |
| 456 | // Check to see if this case stmt overlaps with the subsequent case range. |
| 457 | if (i && CRLo <= HiVals[i-1]) { |
| 458 | OverlapVal = HiVals[i-1]; // Found overlap with range. |
| 459 | OverlapStmt = CaseRanges[i-1].second; |
| 460 | } |
| 461 | |
| 462 | if (OverlapStmt) { |
| 463 | // If we have a duplicate, report it. |
| 464 | Diag(CR->getLHS()->getLocStart(), |
| 465 | diag::err_duplicate_case, OverlapVal.toString()); |
| 466 | Diag(OverlapStmt->getLHS()->getLocStart(), |
| 467 | diag::err_duplicate_case_prev); |
| 468 | // FIXME: We really want to remove the bogus case stmt from the substmt, |
| 469 | // but we have no way to do this right now. |
| 470 | CaseListIsErroneous = true; |
| 471 | } |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 472 | } |
| 473 | } |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 474 | |
Chris Lattner | b2ec9d6 | 2007-08-23 06:23:56 +0000 | [diff] [blame] | 475 | // FIXME: If the case list was broken is some way, we don't have a good system |
| 476 | // to patch it up. Instead, just return the whole substmt as broken. |
| 477 | if (CaseListIsErroneous) |
| 478 | return true; |
Chris Lattner | f4021e7 | 2007-08-23 05:46:52 +0000 | [diff] [blame] | 479 | |
Anders Carlsson | c1fcb77 | 2007-07-22 07:07:56 +0000 | [diff] [blame] | 480 | return SS; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 484 | Sema::ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 485 | Expr *condExpr = (Expr *)Cond; |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 486 | assert(condExpr && "ActOnWhileStmt(): missing expression"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 487 | |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 488 | DefaultFunctionArrayConversion(condExpr); |
| 489 | QualType condType = condExpr->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 490 | |
| 491 | if (!condType->isScalarType()) // C99 6.8.5p2 |
| 492 | return Diag(WhileLoc, diag::err_typecheck_statement_requires_scalar, |
| 493 | condType.getAsString(), condExpr->getSourceRange()); |
| 494 | |
Steve Naroff | b5a6958 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 495 | return new WhileStmt(condExpr, (Stmt*)Body, WhileLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 499 | Sema::ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 500 | SourceLocation WhileLoc, ExprTy *Cond) { |
| 501 | Expr *condExpr = (Expr *)Cond; |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 502 | assert(condExpr && "ActOnDoStmt(): missing expression"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 503 | |
Steve Naroff | c80b4ee | 2007-07-16 21:54:35 +0000 | [diff] [blame] | 504 | DefaultFunctionArrayConversion(condExpr); |
| 505 | QualType condType = condExpr->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 506 | |
| 507 | if (!condType->isScalarType()) // C99 6.8.5p2 |
| 508 | return Diag(DoLoc, diag::err_typecheck_statement_requires_scalar, |
| 509 | condType.getAsString(), condExpr->getSourceRange()); |
| 510 | |
Steve Naroff | b5a6958 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 511 | return new DoStmt((Stmt*)Body, condExpr, DoLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 515 | Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
Chris Lattner | 36c4b0e | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 516 | StmtTy *first, ExprTy *second, ExprTy *third, |
| 517 | SourceLocation RParenLoc, StmtTy *body) { |
| 518 | Stmt *First = static_cast<Stmt*>(first); |
| 519 | Expr *Second = static_cast<Expr*>(second); |
| 520 | Expr *Third = static_cast<Expr*>(third); |
| 521 | Stmt *Body = static_cast<Stmt*>(body); |
| 522 | |
Chris Lattner | ae3b701 | 2007-08-28 05:03:08 +0000 | [diff] [blame] | 523 | if (DeclStmt *DS = dyn_cast_or_null<DeclStmt>(First)) { |
| 524 | // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare |
| 525 | // identifiers for objects having storage class 'auto' or 'register'. |
Ted Kremenek | 909cd26 | 2008-08-08 02:45:18 +0000 | [diff] [blame] | 526 | for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end(); |
| 527 | DI!=DE; ++DI) { |
| 528 | VarDecl *VD = dyn_cast<VarDecl>(*DI); |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 529 | if (VD && VD->isBlockVarDecl() && !VD->hasLocalStorage()) |
| 530 | VD = 0; |
| 531 | if (VD == 0) |
Ted Kremenek | 909cd26 | 2008-08-08 02:45:18 +0000 | [diff] [blame] | 532 | Diag((*DI)->getLocation(), diag::err_non_variable_decl_in_for); |
Chris Lattner | ae3b701 | 2007-08-28 05:03:08 +0000 | [diff] [blame] | 533 | // FIXME: mark decl erroneous! |
| 534 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 535 | } |
| 536 | if (Second) { |
Chris Lattner | 36c4b0e | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 537 | DefaultFunctionArrayConversion(Second); |
| 538 | QualType SecondType = Second->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 539 | |
Chris Lattner | 36c4b0e | 2007-08-28 04:55:47 +0000 | [diff] [blame] | 540 | if (!SecondType->isScalarType()) // C99 6.8.5p2 |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 541 | return Diag(ForLoc, diag::err_typecheck_statement_requires_scalar, |
Chris Lattner | 834a72a | 2008-07-25 23:18:17 +0000 | [diff] [blame] | 542 | SecondType.getAsString(), Second->getSourceRange()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 543 | } |
Steve Naroff | b5a6958 | 2007-08-31 23:28:33 +0000 | [diff] [blame] | 544 | return new ForStmt(First, Second, Third, Body, ForLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 547 | Action::StmtResult |
Fariborz Jahanian | 7571228 | 2008-01-10 00:24:29 +0000 | [diff] [blame] | 548 | Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc, |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 549 | SourceLocation LParenLoc, |
| 550 | StmtTy *first, ExprTy *second, |
| 551 | SourceLocation RParenLoc, StmtTy *body) { |
| 552 | Stmt *First = static_cast<Stmt*>(first); |
| 553 | Expr *Second = static_cast<Expr*>(second); |
| 554 | Stmt *Body = static_cast<Stmt*>(body); |
Fariborz Jahanian | 20552d2 | 2008-01-10 20:33:58 +0000 | [diff] [blame] | 555 | if (First) { |
| 556 | QualType FirstType; |
| 557 | if (DeclStmt *DS = dyn_cast<DeclStmt>(First)) { |
| 558 | FirstType = cast<ValueDecl>(DS->getDecl())->getType(); |
| 559 | // C99 6.8.5p3: The declaration part of a 'for' statement shall only declare |
| 560 | // identifiers for objects having storage class 'auto' or 'register'. |
| 561 | ScopedDecl *D = DS->getDecl(); |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 562 | VarDecl *VD = cast<VarDecl>(D); |
| 563 | if (VD->isBlockVarDecl() && !VD->hasLocalStorage()) |
| 564 | return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for); |
Fariborz Jahanian | 20552d2 | 2008-01-10 20:33:58 +0000 | [diff] [blame] | 565 | if (D->getNextDeclarator()) |
| 566 | return Diag(D->getLocation(), diag::err_toomany_element_decls); |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 567 | } else |
Fariborz Jahanian | 20552d2 | 2008-01-10 20:33:58 +0000 | [diff] [blame] | 568 | FirstType = static_cast<Expr*>(first)->getType(); |
Ted Kremenek | b6ccaac | 2008-07-24 23:58:27 +0000 | [diff] [blame] | 569 | if (!Context.isObjCObjectPointerType(FirstType)) |
Fariborz Jahanian | 20552d2 | 2008-01-10 20:33:58 +0000 | [diff] [blame] | 570 | Diag(ForLoc, diag::err_selector_element_type, |
| 571 | FirstType.getAsString(), First->getSourceRange()); |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 572 | } |
| 573 | if (Second) { |
| 574 | DefaultFunctionArrayConversion(Second); |
| 575 | QualType SecondType = Second->getType(); |
Ted Kremenek | b6ccaac | 2008-07-24 23:58:27 +0000 | [diff] [blame] | 576 | if (!Context.isObjCObjectPointerType(SecondType)) |
Fariborz Jahanian | 7571228 | 2008-01-10 00:24:29 +0000 | [diff] [blame] | 577 | Diag(ForLoc, diag::err_collection_expr_type, |
Fariborz Jahanian | 1f990d6 | 2008-01-04 00:27:46 +0000 | [diff] [blame] | 578 | SecondType.getAsString(), Second->getSourceRange()); |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 579 | } |
Fariborz Jahanian | 7571228 | 2008-01-10 00:24:29 +0000 | [diff] [blame] | 580 | return new ObjCForCollectionStmt(First, Second, Body, ForLoc, RParenLoc); |
Fariborz Jahanian | 3ba5a0f | 2008-01-03 17:55:25 +0000 | [diff] [blame] | 581 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 582 | |
| 583 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 584 | Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 585 | IdentifierInfo *LabelII) { |
| 586 | // Look up the record for this label identifier. |
| 587 | LabelStmt *&LabelDecl = LabelMap[LabelII]; |
| 588 | |
| 589 | // If we haven't seen this label yet, create a forward reference. |
| 590 | if (LabelDecl == 0) |
| 591 | LabelDecl = new LabelStmt(LabelLoc, LabelII, 0); |
| 592 | |
Ted Kremenek | 61f6216 | 2007-09-06 17:11:52 +0000 | [diff] [blame] | 593 | return new GotoStmt(LabelDecl, GotoLoc, LabelLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 597 | Sema::ActOnIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 598 | ExprTy *DestExp) { |
| 599 | // FIXME: Verify that the operand is convertible to void*. |
| 600 | |
| 601 | return new IndirectGotoStmt((Expr*)DestExp); |
| 602 | } |
| 603 | |
| 604 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 605 | Sema::ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 606 | Scope *S = CurScope->getContinueParent(); |
| 607 | if (!S) { |
| 608 | // C99 6.8.6.2p1: A break shall appear only in or as a loop body. |
| 609 | Diag(ContinueLoc, diag::err_continue_not_in_loop); |
| 610 | return true; |
| 611 | } |
| 612 | |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 613 | return new ContinueStmt(ContinueLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 617 | Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 618 | Scope *S = CurScope->getBreakParent(); |
| 619 | if (!S) { |
| 620 | // C99 6.8.6.3p1: A break shall appear only in or as a switch/loop body. |
| 621 | Diag(BreakLoc, diag::err_break_not_in_loop_or_switch); |
| 622 | return true; |
| 623 | } |
| 624 | |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 625 | return new BreakStmt(BreakLoc); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
| 629 | Action::StmtResult |
Steve Naroff | 1b273c4 | 2007-09-16 14:56:35 +0000 | [diff] [blame] | 630 | Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) { |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 631 | Expr *RetValExp = static_cast<Expr *>(rex); |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 632 | QualType FnRetType = |
| 633 | getCurFunctionDecl() ? getCurFunctionDecl()->getResultType() : |
| 634 | getCurMethodDecl()->getResultType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 635 | |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 636 | if (FnRetType->isVoidType()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 637 | if (RetValExp) // C99 6.8.6.4p1 (ext_ since GCC warns) |
Fariborz Jahanian | b107ce8 | 2007-12-04 19:20:11 +0000 | [diff] [blame] | 638 | Diag(ReturnLoc, diag::ext_return_has_expr, |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 639 | ( getCurFunctionDecl() ? |
| 640 | getCurFunctionDecl()->getIdentifier()->getName() : |
| 641 | getCurMethodDecl()->getSelector().getName() ), |
Steve Naroff | 90045e8 | 2007-07-13 23:32:42 +0000 | [diff] [blame] | 642 | RetValExp->getSourceRange()); |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 643 | return new ReturnStmt(ReturnLoc, RetValExp); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 644 | } else { |
| 645 | if (!RetValExp) { |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 646 | const char *funcName = |
| 647 | getCurFunctionDecl() ? |
| 648 | getCurFunctionDecl()->getIdentifier()->getName() : |
| 649 | getCurMethodDecl()->getSelector().getName().c_str(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 650 | if (getLangOptions().C99) // C99 6.8.6.4p1 (ext_ since GCC warns) |
| 651 | Diag(ReturnLoc, diag::ext_return_missing_expr, funcName); |
| 652 | else // C90 6.6.6.4p4 |
| 653 | Diag(ReturnLoc, diag::warn_return_missing_expr, funcName); |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 654 | return new ReturnStmt(ReturnLoc, (Expr*)0); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | // we have a non-void function with an expression, continue checking |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 658 | QualType RetValType = RetValExp->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 659 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 660 | // C99 6.8.6.4p3(136): The return statement is not an assignment. The |
| 661 | // overlap restriction of subclause 6.5.16.1 does not apply to the case of |
| 662 | // function return. |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 663 | AssignConvertType ConvTy = CheckSingleAssignmentConstraints(FnRetType, |
| 664 | RetValExp); |
| 665 | if (DiagnoseAssignmentResult(ConvTy, ReturnLoc, FnRetType, |
| 666 | RetValType, RetValExp, "returning")) |
| 667 | return true; |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 668 | |
Chris Lattner | 5cf216b | 2008-01-04 18:04:52 +0000 | [diff] [blame] | 669 | if (RetValExp) CheckReturnStackAddr(RetValExp, FnRetType, ReturnLoc); |
Ted Kremenek | 06de276 | 2007-08-17 16:46:58 +0000 | [diff] [blame] | 670 | |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 671 | return new ReturnStmt(ReturnLoc, (Expr*)RetValExp); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Anders Carlsson | 6a0ef4b | 2007-11-20 19:21:03 +0000 | [diff] [blame] | 674 | Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 675 | bool IsSimple, |
Anders Carlsson | 39c47b5 | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 676 | bool IsVolatile, |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 677 | unsigned NumOutputs, |
| 678 | unsigned NumInputs, |
| 679 | std::string *Names, |
| 680 | ExprTy **Constraints, |
| 681 | ExprTy **Exprs, |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 682 | ExprTy *asmString, |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 683 | unsigned NumClobbers, |
| 684 | ExprTy **Clobbers, |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 685 | SourceLocation RParenLoc) { |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 686 | // The parser verifies that there is a string literal here. |
| 687 | StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString); |
| 688 | if (AsmString->isWide()) |
| 689 | // FIXME: We currently leak memory here. |
| 690 | return Diag(AsmString->getLocStart(), diag::err_asm_wide_character, |
| 691 | AsmString->getSourceRange()); |
| 692 | |
| 693 | |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 694 | for (unsigned i = 0; i < NumOutputs; i++) { |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 695 | StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]); |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 696 | if (Literal->isWide()) |
| 697 | // FIXME: We currently leak memory here. |
| 698 | return Diag(Literal->getLocStart(), diag::err_asm_wide_character, |
| 699 | Literal->getSourceRange()); |
| 700 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 701 | std::string OutputConstraint(Literal->getStrData(), |
| 702 | Literal->getByteLength()); |
| 703 | |
| 704 | TargetInfo::ConstraintInfo info; |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 705 | if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info)) |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 706 | // FIXME: We currently leak memory here. |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 707 | return Diag(Literal->getLocStart(), |
| 708 | diag::err_invalid_output_constraint_in_asm); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 709 | |
| 710 | // Check that the output exprs are valid lvalues. |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 711 | Expr *OutputExpr = (Expr *)Exprs[i]; |
Chris Lattner | 28be73f | 2008-07-26 21:30:36 +0000 | [diff] [blame] | 712 | Expr::isLvalueResult Result = OutputExpr->isLvalue(Context); |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 713 | if (Result != Expr::LV_Valid) { |
| 714 | ParenExpr *PE = cast<ParenExpr>(OutputExpr); |
| 715 | |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 716 | // FIXME: We currently leak memory here. |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 717 | return Diag(PE->getSubExpr()->getLocStart(), |
| 718 | diag::err_invalid_lvalue_in_asm_output, |
| 719 | PE->getSubExpr()->getSourceRange()); |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 723 | for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) { |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 724 | StringLiteral *Literal = cast<StringLiteral>((Expr *)Constraints[i]); |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 725 | if (Literal->isWide()) |
| 726 | // FIXME: We currently leak memory here. |
| 727 | return Diag(Literal->getLocStart(), diag::err_asm_wide_character, |
| 728 | Literal->getSourceRange()); |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 729 | |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 730 | std::string InputConstraint(Literal->getStrData(), |
| 731 | Literal->getByteLength()); |
| 732 | |
| 733 | TargetInfo::ConstraintInfo info; |
| 734 | if (!Context.Target.validateInputConstraint(InputConstraint.c_str(), |
| 735 | NumOutputs, |
| 736 | info)) { |
| 737 | // FIXME: We currently leak memory here. |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 738 | return Diag(Literal->getLocStart(), |
| 739 | diag::err_invalid_input_constraint_in_asm); |
Anders Carlsson | d04c6e2 | 2007-11-27 04:11:28 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | // Check that the input exprs aren't of type void. |
| 743 | Expr *InputExpr = (Expr *)Exprs[i]; |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 744 | if (InputExpr->getType()->isVoidType()) { |
| 745 | ParenExpr *PE = cast<ParenExpr>(InputExpr); |
| 746 | |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 747 | // FIXME: We currently leak memory here. |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 748 | return Diag(PE->getSubExpr()->getLocStart(), |
| 749 | diag::err_invalid_type_in_asm_input, |
| 750 | PE->getType().getAsString(), |
| 751 | PE->getSubExpr()->getSourceRange()); |
Anders Carlsson | 04728b7 | 2007-11-23 19:43:50 +0000 | [diff] [blame] | 752 | } |
| 753 | } |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 754 | |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 755 | // Check that the clobbers are valid. |
| 756 | for (unsigned i = 0; i < NumClobbers; i++) { |
| 757 | StringLiteral *Literal = cast<StringLiteral>((Expr *)Clobbers[i]); |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 758 | if (Literal->isWide()) |
| 759 | // FIXME: We currently leak memory here. |
| 760 | return Diag(Literal->getLocStart(), diag::err_asm_wide_character, |
| 761 | Literal->getSourceRange()); |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 762 | |
| 763 | llvm::SmallString<16> Clobber(Literal->getStrData(), |
| 764 | Literal->getStrData() + |
| 765 | Literal->getByteLength()); |
| 766 | |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 767 | if (!Context.Target.isValidGCCRegisterName(Clobber.c_str())) |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 768 | // FIXME: We currently leak memory here. |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 769 | return Diag(Literal->getLocStart(), |
| 770 | diag::err_unknown_register_name_in_asm, Clobber.c_str()); |
Anders Carlsson | 6fa9086 | 2007-11-25 00:25:21 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 773 | return new AsmStmt(AsmLoc, |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 774 | IsSimple, |
Anders Carlsson | 39c47b5 | 2007-11-23 23:12:25 +0000 | [diff] [blame] | 775 | IsVolatile, |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 776 | NumOutputs, |
| 777 | NumInputs, |
| 778 | Names, |
| 779 | reinterpret_cast<StringLiteral**>(Constraints), |
| 780 | reinterpret_cast<Expr**>(Exprs), |
Chris Lattner | 6bc5211 | 2008-07-23 06:46:56 +0000 | [diff] [blame] | 781 | AsmString, NumClobbers, |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 782 | reinterpret_cast<StringLiteral**>(Clobbers), |
| 783 | RParenLoc); |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 784 | } |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 785 | |
| 786 | Action::StmtResult |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 787 | Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 788 | SourceLocation RParen, StmtTy *Parm, |
| 789 | StmtTy *Body, StmtTy *CatchList) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 790 | ObjCAtCatchStmt *CS = new ObjCAtCatchStmt(AtLoc, RParen, |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 791 | static_cast<Stmt*>(Parm), static_cast<Stmt*>(Body), |
| 792 | static_cast<Stmt*>(CatchList)); |
| 793 | return CatchList ? CatchList : CS; |
| 794 | } |
| 795 | |
Fariborz Jahanian | 161a9c5 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 796 | Action::StmtResult |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 797 | Sema::ActOnObjCAtFinallyStmt(SourceLocation AtLoc, StmtTy *Body) { |
| 798 | ObjCAtFinallyStmt *FS = new ObjCAtFinallyStmt(AtLoc, |
Fariborz Jahanian | 161a9c5 | 2007-11-02 00:18:53 +0000 | [diff] [blame] | 799 | static_cast<Stmt*>(Body)); |
| 800 | return FS; |
| 801 | } |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 802 | |
| 803 | Action::StmtResult |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 804 | Sema::ActOnObjCAtTryStmt(SourceLocation AtLoc, |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 805 | StmtTy *Try, StmtTy *Catch, StmtTy *Finally) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 806 | ObjCAtTryStmt *TS = new ObjCAtTryStmt(AtLoc, static_cast<Stmt*>(Try), |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 807 | static_cast<Stmt*>(Catch), |
| 808 | static_cast<Stmt*>(Finally)); |
| 809 | return TS; |
| 810 | } |
| 811 | |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 812 | Action::StmtResult |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 813 | Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, StmtTy *Throw) { |
| 814 | ObjCAtThrowStmt *TS = new ObjCAtThrowStmt(AtLoc, static_cast<Stmt*>(Throw)); |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 815 | return TS; |
| 816 | } |
Fariborz Jahanian | bd49a64 | 2007-11-02 15:39:31 +0000 | [diff] [blame] | 817 | |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 818 | Action::StmtResult |
| 819 | Sema::ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, ExprTy *SynchExpr, |
| 820 | StmtTy *SynchBody) { |
| 821 | ObjCAtSynchronizedStmt *SS = new ObjCAtSynchronizedStmt(AtLoc, |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 822 | static_cast<Stmt*>(SynchExpr), static_cast<Stmt*>(SynchBody)); |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 823 | return SS; |
| 824 | } |