00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027 #include <iostream>
00028 #include "ShBlock.hpp"
00029 #include "ShStatement.hpp"
00030 #include "ShBasicBlock.hpp"
00031
00032 namespace SH {
00033
00034 ShBlock::~ShBlock()
00035 {
00036 }
00037
00038
00039
00040 ShBlockList::ShBlockList(bool isArgument)
00041 : m_isArgument(isArgument)
00042 {
00043 }
00044
00045 bool ShBlockList::isArgument()
00046 {
00047 return m_isArgument;
00048 }
00049
00050 void ShBlockList::addStatement(const ShStatement& statement)
00051 {
00052 ShBasicBlockPtr basicBlock;
00053 if (!m_blocks.empty()) {
00054 basicBlock = shref_dynamic_cast<ShBasicBlock>(m_blocks.back());
00055 if (!basicBlock) {
00056 basicBlock = new ShBasicBlock();
00057 m_blocks.push_back(ShBlockPtr(basicBlock));
00058 }
00059 } else {
00060 basicBlock = new ShBasicBlock();
00061 m_blocks.push_back(ShBlockPtr(basicBlock));
00062 }
00063 basicBlock->addStatement(statement);
00064 }
00065
00066 void ShBlockList::addBlock(const ShBlockPtr& statement)
00067 {
00068 m_blocks.push_back(statement);
00069 }
00070
00071 ShBlockPtr ShBlockList::getFront() const
00072 {
00073 if (m_blocks.empty()) return 0;
00074
00075 return m_blocks.front();
00076 }
00077
00078 ShBlockPtr ShBlockList::removeFront()
00079 {
00080 if (m_blocks.empty()) return 0;
00081
00082 ShBlockPtr front = m_blocks.front();
00083 m_blocks.erase(m_blocks.begin());
00084 return front;
00085 }
00086
00087 bool ShBlockList::empty() const
00088 {
00089 return m_blocks.empty();
00090 }
00091
00092 std::ostream& ShBlockList::print(std::ostream& out, int indent) const
00093 {
00094 for (std::vector<ShBlockPtr>::const_iterator I = m_blocks.begin();
00095 I != m_blocks.end(); ++I) {
00096 (*I)->print(out, indent);
00097 }
00098 return out;
00099 }
00100
00101 std::ostream& operator<<(std::ostream& out, const ShBlockList& l)
00102 {
00103 l.print(out, 0);
00104 return out;
00105
00106 }
00107
00108
00109 }
00110
00111