blob: d0fec64e042e99abf496bdc93b8c01a2625284ee [file] [log] [blame]
Chris Lattneraf8d5812006-11-10 05:07:45 +00001//===--- 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"
16using namespace llvm;
17using namespace clang;
18
19
20Action::StmtResult
21Sema::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
31Action::StmtResult
32Sema::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
38Action::StmtResult
39Sema::ParseDefaultStmt(SourceLocation DefaultLoc,
40 SourceLocation ColonLoc, StmtTy *SubStmt) {
41 return new DefaultStmt((Stmt*)SubStmt);
42}
43
44Action::StmtResult
45Sema::ParseLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
46 SourceLocation ColonLoc, StmtTy *SubStmt) {
47 return new LabelStmt(II, (Stmt*)SubStmt);
48}
49
50Action::StmtResult
51Sema::ParseIfStmt(SourceLocation IfLoc, ExprTy *CondVal,
52 StmtTy *ThenVal, SourceLocation ElseLoc,
53 StmtTy *ElseVal) {
54 return new IfStmt((Expr*)CondVal, (Stmt*)ThenVal, (Stmt*)ElseVal);
55}
56Action::StmtResult
57Sema::ParseSwitchStmt(SourceLocation SwitchLoc, ExprTy *Cond, StmtTy *Body) {
58 return new SwitchStmt((Expr*)Cond, (Stmt*)Body);
59}
60
61Action::StmtResult
62Sema::ParseWhileStmt(SourceLocation WhileLoc, ExprTy *Cond, StmtTy *Body){
63 return new WhileStmt((Expr*)Cond, (Stmt*)Body);
64}
65
66Action::StmtResult
67Sema::ParseDoStmt(SourceLocation DoLoc, StmtTy *Body,
68 SourceLocation WhileLoc, ExprTy *Cond) {
69 return new DoStmt((Stmt*)Body, (Expr*)Cond);
70}
71
72Action::StmtResult
73Sema::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
80Action::StmtResult
81Sema::ParseGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
82 IdentifierInfo *LabelII) {
83 return new GotoStmt(LabelII);
84}
85Action::StmtResult
86Sema::ParseIndirectGotoStmt(SourceLocation GotoLoc,SourceLocation StarLoc,
87 ExprTy *DestExp) {
88 return new IndirectGotoStmt((Expr*)DestExp);
89}
90
91Action::StmtResult
92Sema::ParseContinueStmt(SourceLocation ContinueLoc) {
93 return new ContinueStmt();
94}
95
96Action::StmtResult
97Sema::ParseBreakStmt(SourceLocation GotoLoc) {
98 return new BreakStmt();
99}
100
101
102Action::StmtResult
103Sema::ParseReturnStmt(SourceLocation ReturnLoc, ExprTy *RetValExp) {
104 return new ReturnStmt((Expr*)RetValExp);
105}
106