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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "c_breeze.h"
00039
00040
00041
00042
00043
00044 blockNode::blockNode(decl_list * decls, stmt_list * stmts,
00045 const Coord left_coord, const Coord right_brace)
00046 : stmtNode(Block, left_coord),
00047 _decls(),
00048 _stmts(),
00049 _right_brace(right_brace)
00050 {
00051 if (decls) {
00052 _decls.swap(* decls);
00053
00054 }
00055
00056 if (stmts) {
00057 _stmts.swap(* stmts);
00058
00059 }
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 blockNode * blockNode::toBlock(stmtNode *stmt, Coord coord)
00069 {
00070 if (stmt && (stmt->typ() != Block)) {
00071 stmt_list * stmts = new stmt_list();
00072 stmts->push_front(stmt);
00073 return new blockNode((decl_list *)0, stmts, coord);
00074 }
00075 else
00076 return (blockNode *)stmt;
00077 }
00078
00079
00080
00081
00082
00083 typeNode * blockNode::base_type(bool TdefIndir) const
00084 {
00085 return (typeNode *) 0;
00086 }
00087
00088
00089
00090
00091
00092 void blockNode::visit(Visitor * the_visitor)
00093 {
00094 the_visitor->at_block(this);
00095 }
00096
00097 void blockNode::walk(Walker & the_walker)
00098 {
00099 Walker::Order ord = the_walker.order();
00100
00101 if (ord == Walker::Preorder || ord == Walker::Both)
00102 the_walker.at_block(this, Walker::Preorder);
00103
00104 if (the_walker.depth() == Walker::Subtree) {
00105
00106
00107 list_walker(decls(), the_walker);
00108 list_walker(stmts(), the_walker);
00109
00110 }
00111
00112 if (ord == Walker::Postorder || ord == Walker::Both)
00113 the_walker.at_block(this, Walker::Postorder);
00114 }
00115
00116
00117
00118
00119
00120 void blockNode::dataflow(FlowVal * v, FlowProblem & fp)
00121 {
00122 if (fp.forward()) {
00123 fp.flow_block(v, this, FlowProblem::Entry);
00124
00125 dataflow_forward_list(decls(), v, fp);
00126 dataflow_forward_list(stmts(), v, fp);
00127
00128 fp.flow_block(v, this, FlowProblem::Exit);
00129 }
00130 else {
00131 fp.flow_block(v, this, FlowProblem::Exit);
00132
00133 dataflow_reverse_list(stmts(), v, fp);
00134 dataflow_reverse_list(decls(), v, fp);
00135
00136 fp.flow_block(v, this, FlowProblem::Entry);
00137 }
00138 }
00139
00140
00141
00142
00143
00144 void blockNode::output_stmt(output_context & ct, Node * parent)
00145 {
00146 int ds = decls().size();
00147 int ss = stmts().size();
00148 int l = ds + ss;
00149 NodeType parent_type;
00150
00151 if (parent)
00152 parent_type = parent->typ();
00153 else
00154 parent_type = Proc;
00155
00156 if ((parent_type == Block) ||
00157 (parent_type == Proc))
00158 ct.new_line();
00159
00160 if ((l != 1) || (parent_type == Proc) || (parent_type == If)) {
00161 ct << '{';
00162 CBZ::current_unit->enter_scope();
00163 }
00164
00165 ct.indent_in();
00166
00167 output_comment(ct);
00168
00169 output_list(decls(), ct, this);
00170
00171 if ((ds > 0) && (ss > 0))
00172 ct.new_line();
00173
00174 output_list(stmts(), ct, this);
00175
00176 ct.indent_out();
00177
00178 if ((l != 1) || (parent_type == Proc) || (parent_type == If)) {
00179
00180
00181
00182
00183
00184 #ifdef FOOO
00185
00186 for (suespec_list_p p=CBZ::current_unit->suespecs().begin();
00187 p!=CBZ::current_unit->suespecs().end(); p++) {
00188 if ((*p)->scope_output() >= CBZ::current_unit->symbol_level()) {
00189 (*p)->already_output(false);
00190 }
00191 }
00192 #endif
00193 CBZ::current_unit->exit_scope();
00194 ct.new_line();
00195 ct << '}';
00196 }
00197 }
00198
00199
00200
00201
00202
00203 Node * blockNode::change(Changer & the_changer, bool redispatch)
00204 {
00205 Changer::Order ord = the_changer.order();
00206 blockNode * the_block = this;
00207
00208 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00209 the_block = (blockNode *) the_changer.at_block(the_block, Changer::Preorder);
00210
00211 if (the_block) {
00212
00213 if (the_block != this)
00214 return the_block->change(the_changer, true);
00215
00216 change_list(the_block->decls(), the_changer);
00217
00218 change_list(the_block->stmts(), the_changer);
00219 }
00220
00221 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00222 the_block = (blockNode *) the_changer.at_block(the_block, Changer::Postorder);
00223
00224 return the_block;
00225 }
00226
00227
00228
00229
00230
00231
00232 blockNode::~blockNode()
00233 {
00234
00235
00236 }