Chris Lattner | af8d581 | 2006-11-10 05:07:45 +0000 | [diff] [blame^] | 1 | //===--- SemaStmt.cpp - Semantic Analysis for Statements ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for statements. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Sema.h" |
| 15 | #include "clang/AST/Stmt.h" |
| 16 | using namespace llvm; |
| 17 | using namespace clang; |
| 18 | |
| 19 | |
| 20 | Action::StmtResult |
| 21 | Sema::ParseCompoundStmt(SourceLocation L, SourceLocation R, |
| 22 | StmtTy **Elts, unsigned NumElts) { |
| 23 | if (NumElts > 1) |
| 24 | return new CompoundStmt((Stmt**)Elts, NumElts); |
| 25 | else if (NumElts == 1) |
| 26 | return Elts[0]; // {stmt} -> stmt |
| 27 | else |
| 28 | return 0; // {} -> ; |
| 29 | } |
| 30 | |
| 31 | Action::StmtResult |
| 32 | Sema::ParseCaseStmt(SourceLocation CaseLoc, ExprTy *LHSVal, |
| 33 | SourceLocation DotDotDotLoc, ExprTy *RHSVal, |
| 34 | SourceLocation ColonLoc, StmtTy *SubStmt) { |
| 35 | return new CaseStmt((Expr*)LHSVal, (Expr*)RHSVal, (Stmt*)SubStmt); |
| 36 | } |
| 37 | |
| 38 | Action::StmtResult |
| 39 | Sema::ParseDefaultStmt(SourceLocation DefaultLoc, |
| 40 | SourceLocation ColonLoc, StmtTy *SubStmt) { |
| 41 | return new DefaultStmt((Stmt*)SubStmt); |
| 42 | } |
| 43 | |
| 44 | Action::StmtResult |
| 45 | Sema::ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II, |
| 46 | SourceLocation ColonLoc, StmtTy *SubStmt) { |
| 47 | return new LabelStmt(II, (Stmt*)SubStmt); |
| 48 | } |
| 49 | |
| 50 | Action::StmtResult |
| 51 | Sema::ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal, |
| 52 | StmtTy *ThenVal, SourceLocation ElseLoc, |
| 53 | StmtTy *ElseVal) { |
| 54 | return new IfStmt((Expr*)CondVal, (Stmt*)ThenVal, (Stmt*)ElseVal); |
| 55 | } |
| 56 | Action::StmtResult |
| 57 | Sema::ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond, StmtTy *Body) { |
| 58 | return new SwitchStmt((Expr*)Cond, (Stmt*)Body); |
| 59 | } |
| 60 | |
| 61 | Action::StmtResult |
| 62 | Sema::ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body){ |
| 63 | return new WhileStmt((Expr*)Cond, (Stmt*)Body); |
| 64 | } |
| 65 | |
| 66 | Action::StmtResult |
| 67 | Sema::ParseDoStmt(SourceLocation DoLoc, StmtTy *Body, |
| 68 | SourceLocation WhileLoc, ExprTy *Cond) { |
| 69 | return new DoStmt((Stmt*)Body, (Expr*)Cond); |
| 70 | } |
| 71 | |
| 72 | Action::StmtResult |
| 73 | Sema::ParseForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 74 | StmtTy *First, ExprTy *Second, ExprTy *Third, |
| 75 | SourceLocation RParenLoc, StmtTy *Body) { |
| 76 | return new ForStmt((Stmt*)First, (Expr*)Second, (Expr*)Third, (Stmt*)Body); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | Action::StmtResult |
| 81 | Sema::ParseGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 82 | IdentifierInfo *LabelII) { |
| 83 | return new GotoStmt(LabelII); |
| 84 | } |
| 85 | Action::StmtResult |
| 86 | Sema::ParseIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc, |
| 87 | ExprTy *DestExp) { |
| 88 | return new IndirectGotoStmt((Expr*)DestExp); |
| 89 | } |
| 90 | |
| 91 | Action::StmtResult |
| 92 | Sema::ParseContinueStmt(SourceLocation ContinueLoc) { |
| 93 | return new ContinueStmt(); |
| 94 | } |
| 95 | |
| 96 | Action::StmtResult |
| 97 | Sema::ParseBreakStmt(SourceLocation GotoLoc) { |
| 98 | return new BreakStmt(); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | Action::StmtResult |
| 103 | Sema::ParseReturnStmt(SourceLocation ReturnLoc, ExprTy *RetValExp) { |
| 104 | return new ReturnStmt((Expr*)RetValExp); |
| 105 | } |
| 106 | |