blob: 7d2a1052d8487b53c3b44b8492ba7bd4686dc786 [file] [log] [blame]
Chris Lattnerf42cce72006-10-25 04:09:21 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
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 the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Stmt.h"
15#include "clang/AST/Expr.h"
Chris Lattner5e9a8782006-11-04 06:21:51 +000016#include "clang/AST/StmtVisitor.h"
Chris Lattnerf42cce72006-10-25 04:09:21 +000017#include <iostream>
18using namespace llvm;
19using namespace clang;
20
21void Stmt::dump() const {
22 if (this == 0) {
23 std::cerr << "<null>";
24 return;
25 }
Chris Lattner6d9a6852006-10-25 05:11:20 +000026 if (isExpr()) std::cerr << "(";
Chris Lattnerf42cce72006-10-25 04:09:21 +000027 dump_impl();
Chris Lattner6d9a6852006-10-25 05:11:20 +000028 if (isExpr()) std::cerr << ")";
Chris Lattnerf42cce72006-10-25 04:09:21 +000029}
Chris Lattnere5cca062006-10-25 04:29:46 +000030
31
Chris Lattner5e9a8782006-11-04 06:21:51 +000032void CompoundStmt::visit(StmtVisitor *V) { return V->VisitCompoundStmt(this); }
33void IfStmt ::visit(StmtVisitor *V) { return V->VisitIfStmt(this); }
34void ReturnStmt ::visit(StmtVisitor *V) { return V->VisitReturnStmt(this); }
35
Chris Lattnere5cca062006-10-25 04:29:46 +000036
37void CompoundStmt::dump_impl() const {
38 std::cerr << "{\n";
Chris Lattner6d9a6852006-10-25 05:11:20 +000039 for (unsigned i = 0, e = Body.size(); i != e; ++i) {
Chris Lattnere5cca062006-10-25 04:29:46 +000040 Body[i]->dump();
Chris Lattner6d9a6852006-10-25 05:11:20 +000041 std::cerr << "\n";
42 }
Chris Lattnere5cca062006-10-25 04:29:46 +000043 std::cerr << "}";
44}
45
Chris Lattner5f84a062006-10-25 05:55:20 +000046void IfStmt::dump_impl() const {
47 std::cerr << "if ";
48 Cond->dump();
49 std::cerr << " then\n";
50 Then->dump();
51 std::cerr << "\n else ";
52 Else->dump();
53}
Chris Lattnere5cca062006-10-25 04:29:46 +000054
55void ReturnStmt::dump_impl() const {
56 std::cerr << "return ";
57 if (RetExpr)
58 RetExpr->dump();
59}