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 returnNode::returnNode(exprNode * expr, procNode * proc, const Coord coord)
00045 : jumpNode(Return, coord),
00046 _expr(expr),
00047 _proc(proc),
00048 _is_proc_exit(false)
00049 {}
00050
00051 returnNode::returnNode(exprNode * expr, procNode * proc, bool proc_exit,
00052 const Coord coord):
00053 jumpNode(Return, coord),
00054 _expr(expr),
00055 _proc(proc),
00056 _is_proc_exit(proc_exit)
00057 {}
00058
00059
00060
00061
00062
00063 void returnNode::visit(Visitor * the_visitor)
00064 {
00065 the_visitor->at_return(this);
00066 }
00067
00068 void returnNode::walk(Walker & the_walker)
00069 {
00070 Walker::Order ord = the_walker.order();
00071
00072 if (ord == Walker::Preorder || ord == Walker::Both)
00073 the_walker.at_return(this, Walker::Preorder);
00074
00075 if (the_walker.depth() == Walker::Subtree) {
00076
00077
00078 if (expr())
00079 expr()->walk(the_walker);
00080 }
00081
00082 if (ord == Walker::Postorder || ord == Walker::Both)
00083 the_walker.at_return(this, Walker::Postorder);
00084 }
00085
00086
00087
00088
00089
00090 void returnNode::dataflow(FlowVal * v, FlowProblem & fp)
00091 {
00092 if (fp.forward()) {
00093 fp.flow_return(v, this, FlowProblem::Entry);
00094
00095
00096
00097 if (expr())
00098 if (fp.basicblocks()) {
00099 fp.flow_basicblock(v, expr(), FlowProblem::Entry);
00100 fp.flow_basicblock(v, expr(), FlowProblem::Exit);
00101 }
00102 else
00103 expr()->dataflow(v, fp);
00104
00105 if (proc())
00106 proc()->at_exit()->meet_and_diff(v, fp);
00107
00108 v->to_top();
00109
00110 fp.flow_return(v, this, FlowProblem::Exit);
00111 }
00112 else {
00113 fp.flow_return(v, this, FlowProblem::Exit);
00114
00115
00116
00117 v->to_top();
00118
00119 if (proc())
00120 v->meet(proc()->at_exit());
00121
00122 if (expr())
00123 if (fp.basicblocks()) {
00124 fp.flow_basicblock(v, expr(), FlowProblem::Exit);
00125 fp.flow_basicblock(v, expr(), FlowProblem::Entry);
00126 }
00127 else
00128 expr()->dataflow(v, fp);
00129
00130 fp.flow_return(v, this, FlowProblem::Entry);
00131 }
00132 }
00133
00134
00135
00136 Node * returnNode::clone() const {
00137 returnNode * ret = new returnNode(*this);
00138 ret->proc_exit(false);
00139 return ret;
00140 }
00141
00142
00143
00144
00145
00146 void returnNode::output_stmt(output_context & ct, Node * parent)
00147 {
00148 ct << "return ";
00149 if (expr())
00150 expr()->output(ct, this);
00151 ct << ';';
00152 }
00153
00154
00155
00156
00157
00158 Node * returnNode::change(Changer & the_changer, bool redispatch)
00159 {
00160 Changer::Order ord = the_changer.order();
00161 returnNode * the_return = this;
00162
00163 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00164 the_return = (returnNode *) the_changer.at_return(the_return, Changer::Preorder);
00165
00166 if (the_return) {
00167
00168 if (the_return != this)
00169 return the_return->change(the_changer, true);
00170
00171 exprNode * old_expr = the_return->expr();
00172 if (old_expr) {
00173 exprNode * new_expr = (exprNode *) old_expr->change(the_changer);
00174 if (old_expr != new_expr) {
00175
00176
00177 the_return->expr(new_expr);
00178 }
00179 }
00180
00181 }
00182
00183 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00184 the_return = (returnNode *) the_changer.at_return(the_return, Changer::Postorder);
00185
00186 return the_return;
00187 }
00188
00189
00190
00191
00192
00193
00194 returnNode::~returnNode()
00195 {
00196
00197 }