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 constNode::constNode(constant val, const char * text, const Coord coord)
00045 : indexNode(Const, 0, coord),
00046 _text(string(text))
00047 {
00048 value(val);
00049
00050 if (val.is_str())
00051
00052 type(new arrayNode(typeNode::NONE,
00053 new primNode(basic_type::Char),
00054 new constNode(constant(strlen(val.Str())+1))));
00055 else
00056 if (val.is_ptr())
00057
00058 type(new ptrNode(typeNode::NONE,
00059 new primNode(basic_type::Void)));
00060 else
00061
00062 type(new primNode(val.basic()));
00063 }
00064
00065
00066
00067
00068
00069 void constNode::eval()
00070 {
00071
00072 }
00073
00074
00075
00076
00077
00078 void constNode::visit(Visitor * the_visitor)
00079 {
00080 the_visitor->at_const(this);
00081 }
00082
00083 void constNode::walk(Walker & the_walker)
00084 {
00085 Walker::Order ord = the_walker.order();
00086
00087 if (ord == Walker::Preorder || ord == Walker::Both)
00088 the_walker.at_const(this, Walker::Preorder);
00089
00090 if (the_walker.depth() == Walker::Subtree) {
00091
00092
00093 if (type())
00094 type()->walk(the_walker);
00095 }
00096
00097 if (ord == Walker::Postorder || ord == Walker::Both)
00098 the_walker.at_const(this, Walker::Postorder);
00099 }
00100
00101
00102
00103
00104
00105 void constNode::dataflow(FlowVal * v, FlowProblem & fp)
00106 {
00107 if (fp.forward()) {
00108 fp.flow_const(v, this, FlowProblem::Entry);
00109 fp.flow_const(v, this, FlowProblem::Exit);
00110 }
00111 else {
00112 fp.flow_const(v, this, FlowProblem::Exit);
00113 fp.flow_const(v, this, FlowProblem::Entry);
00114 }
00115 }
00116
00117
00118
00119
00120
00121 void constNode::output_expr(output_context & ct, Node * parent, int prec, Assoc assoc)
00122 {
00123 bool par = parens(prec, assoc);
00124
00125 if (par)
00126 ct << '(';
00127
00128
00129 if (! text().empty())
00130 ct << text();
00131 else
00132 ct << value().to_string();
00133
00134 if (par)
00135 ct << ')';
00136 }
00137
00138
00139
00140
00141
00142 Node * constNode::change(Changer & the_changer, bool redispatch)
00143 {
00144 Changer::Order ord = the_changer.order();
00145 constNode * the_const = this;
00146
00147 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00148 the_const = (constNode *) the_changer.at_const(the_const, Changer::Preorder);
00149
00150 if (the_const) {
00151
00152 if (the_const != this)
00153 return the_const->change(the_changer, true);
00154
00155 typeNode * old_type = the_const->type();
00156 if (old_type) {
00157 typeNode * new_type = (typeNode *) old_type->change(the_changer);
00158 if (old_type != new_type) {
00159
00160
00161 the_const->type(new_type);
00162 }
00163 }
00164
00165 }
00166
00167 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00168 the_const = (constNode *) the_changer.at_const(the_const, Changer::Postorder);
00169
00170 return the_const;
00171 }
00172
00173
00174
00175
00176
00177
00178 constNode::~constNode()
00179 {
00180 }