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 switchNode::switchNode(exprNode * expr, stmtNode * stmt, const Coord coord)
00045 : selectionNode(Switch, expr, stmt, coord),
00046 _cases(),
00047 _has_default(false)
00048 {}
00049
00050
00051
00052
00053
00054 void switchNode::visit(Visitor * the_visitor)
00055 {
00056 the_visitor->at_switch(this);
00057 }
00058
00059 void switchNode::walk(Walker & the_walker)
00060 {
00061 Walker::Order ord = the_walker.order();
00062
00063 if (ord == Walker::Preorder || ord == Walker::Both)
00064 the_walker.at_switch(this, Walker::Preorder);
00065
00066 if (the_walker.depth() == Walker::Subtree) {
00067
00068
00069 if (expr())
00070 expr()->walk(the_walker);
00071
00072 if (stmt())
00073 stmt()->walk(the_walker);
00074 }
00075
00076 if (ord == Walker::Postorder || ord == Walker::Both)
00077 the_walker.at_switch(this, Walker::Postorder);
00078 }
00079
00080
00081
00082
00083
00084 void switchNode::dataflow(FlowVal * v, FlowProblem & fp)
00085 {
00086 if (fp.forward()) {
00087 fp.flow_switch(v, this, FlowProblem::Entry);
00088
00089 if (expr())
00090 if (fp.basicblocks()) {
00091 fp.flow_basicblock(v, expr(), FlowProblem::Entry);
00092 fp.flow_basicblock(v, expr(), FlowProblem::Exit);
00093 }
00094 else
00095 expr()->dataflow(v, fp);
00096
00097
00098
00099 at_top()->meet_and_diff(v, fp);
00100
00101
00102
00103 if (! has_default())
00104 at_exit()->meet_and_diff(v, fp);
00105
00106
00107
00108
00109 v->to_top();
00110
00111 if (stmt())
00112 stmt()->dataflow(v, fp);
00113
00114
00115
00116 v->meet(at_exit());
00117
00118 fp.flow_switch(v, this, FlowProblem::Exit);
00119 }
00120 else {
00121 fp.flow_switch(v, this, FlowProblem::Exit);
00122
00123
00124
00125 at_exit()->meet_and_diff(v, fp);
00126
00127
00128
00129 if (! has_default())
00130 at_top()->meet_and_diff(at_exit(), fp);
00131
00132
00133
00134 if (stmt())
00135 stmt()->dataflow(v, fp);
00136
00137
00138
00139
00140 v->to_top();
00141 v->meet(at_top());
00142
00143 if (expr())
00144 if (fp.basicblocks()) {
00145 fp.flow_basicblock(v, expr(), FlowProblem::Exit);
00146 fp.flow_basicblock(v, expr(), FlowProblem::Entry);
00147 }
00148 else
00149 expr()->dataflow(v, fp);
00150
00151 fp.flow_switch(v, this, FlowProblem::Entry);
00152 }
00153 }
00154
00155
00156
00157
00158
00159 void switchNode::output_stmt(output_context & ct, Node * parent)
00160 {
00161 ct << "switch " << '(';
00162
00163 if (expr())
00164 expr()->output(ct, this);
00165
00166 ct << ')';
00167 ct.space();
00168
00169 if (stmt())
00170 stmt()->output(ct, this);
00171 else
00172 ct << ';';
00173 }
00174
00175
00176
00177
00178
00179 Node * switchNode::change(Changer & the_changer, bool redispatch)
00180 {
00181 Changer::Order ord = the_changer.order();
00182 switchNode * the_switch = this;
00183
00184 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00185 the_switch = (switchNode *) the_changer.at_switch(the_switch, Changer::Preorder);
00186
00187 if (the_switch) {
00188
00189 if (the_switch != this)
00190 return the_switch->change(the_changer, true);
00191
00192 exprNode * old_expr = the_switch->expr();
00193 if (old_expr) {
00194 exprNode * new_expr = (exprNode *) old_expr->change(the_changer);
00195 if (old_expr != new_expr) {
00196
00197
00198 the_switch->expr(new_expr);
00199 }
00200 }
00201
00202 blockNode * old_stmt = the_switch->stmt();
00203 if (old_stmt) {
00204 blockNode * new_stmt = (blockNode *) old_stmt->change(the_changer);
00205 if (old_stmt != new_stmt) {
00206
00207
00208 the_switch->stmt(new_stmt);
00209 }
00210 }
00211
00212 }
00213
00214 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00215 the_switch = (switchNode *) the_changer.at_switch(the_switch, Changer::Postorder);
00216
00217 return the_switch;
00218 }
00219
00220
00221
00222
00223
00224
00225 switchNode::~switchNode()
00226 {
00227 }