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 castNode::castNode(typeNode * type, exprNode * expr, bool implicit,
00045 const Coord coord)
00046 : exprNode(Cast, type, coord),
00047 _expr(expr),
00048 _implicit(implicit)
00049 {}
00050
00051
00052
00053
00054
00055 int castNode::precedence(Assoc & assoc)
00056 {
00057 assoc = Right;
00058 return 14;
00059 }
00060
00061
00062
00063
00064
00065 void castNode::eval()
00066 {
00067
00068
00069 expr()->eval();
00070
00071
00072
00073 if (type()->typ() == Prim) {
00074
00075
00076
00077 primNode * p = (primNode *) type();
00078 const basic_type & bt = p->basic();
00079
00080
00081
00082 value(constant::cast(bt, expr()->value()));
00083 }
00084 else
00085 value(constant());
00086 }
00087
00088
00089
00090
00091
00092 void castNode::visit(Visitor * the_visitor)
00093 {
00094 the_visitor->at_cast(this);
00095 }
00096
00097 void castNode::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_cast(this, Walker::Preorder);
00103
00104 if (the_walker.depth() == Walker::Subtree) {
00105
00106
00107 if (type())
00108 type()->walk(the_walker);
00109
00110 if (expr())
00111 expr()->walk(the_walker);
00112 }
00113
00114 if (ord == Walker::Postorder || ord == Walker::Both)
00115 the_walker.at_cast(this, Walker::Postorder);
00116 }
00117
00118
00119
00120
00121
00122 void castNode::dataflow(FlowVal * v, FlowProblem & fp)
00123 {
00124 if (fp.forward()) {
00125 fp.flow_cast(v, this, FlowProblem::Entry);
00126
00127 if (expr())
00128 expr()->dataflow(v, fp);
00129
00130 fp.flow_cast(v, this, FlowProblem::Exit);
00131 }
00132 else {
00133 fp.flow_cast(v, this, FlowProblem::Exit);
00134
00135 if (expr())
00136 expr()->dataflow(v, fp);
00137
00138 fp.flow_cast(v, this, FlowProblem::Entry);
00139 }
00140 }
00141
00142
00143
00144
00145
00146 void castNode::output_expr(output_context & ct, Node * parent, int prec, Assoc assoc)
00147 {
00148
00149 if (is_implicit())
00150 expr()->output_expr(ct, this, prec, assoc);
00151 else {
00152
00153 bool par = parens(prec, assoc);
00154 int myprec;
00155 Assoc myassoc;
00156
00157 myprec = precedence(myassoc);
00158
00159 if (par)
00160 ct << '(';
00161
00162 ct << '(';
00163 type()->output(ct, this);
00164 ct << ')';
00165 ct.space();
00166 expr()->output_expr(ct, this, myprec, Right);
00167
00168 if (par)
00169 ct << ')';
00170 }
00171 }
00172
00173
00174
00175
00176
00177 Node * castNode::change(Changer & the_changer, bool redispatch)
00178 {
00179 Changer::Order ord = the_changer.order();
00180 castNode * the_cast = this;
00181
00182 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00183 the_cast = (castNode *) the_changer.at_cast(the_cast, Changer::Preorder);
00184
00185 if (the_cast) {
00186
00187 if (the_cast != this)
00188 return the_cast->change(the_changer, true);
00189
00190 typeNode * old_type = the_cast->type();
00191 if (old_type) {
00192 typeNode * new_type = (typeNode *) old_type->change(the_changer);
00193 if (old_type != new_type) {
00194
00195
00196 the_cast->type(new_type);
00197 }
00198 }
00199
00200 exprNode * old_expr = the_cast->expr();
00201 if (old_expr) {
00202 exprNode * new_expr = (exprNode *) old_expr->change(the_changer);
00203 if (old_expr != new_expr) {
00204
00205
00206 the_cast->expr(new_expr);
00207 }
00208 }
00209
00210 }
00211
00212 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00213 the_cast = (castNode *) the_changer.at_cast(the_cast, Changer::Postorder);
00214
00215 return the_cast;
00216 }
00217
00218
00219
00220
00221
00222
00223 castNode::~castNode()
00224 {
00225
00226 }