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