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 #include "ref_clone_changer.h"
00040
00041
00042
00043
00044
00045 idNode::idNode(const char * text, const Coord coord)
00046 : indexNode(Id, 0, coord),
00047 _name(string(text)),
00048 _decl(0)
00049 {}
00050
00051 idNode::idNode(declNode * the_decl, const Coord coord)
00052 : indexNode(Id, 0, coord),
00053 _name(the_decl->name()),
00054 _decl(0)
00055 {
00056 if (the_decl) {
00057 _name = the_decl->name();
00058 this->decl(the_decl);
00059 }
00060 }
00061
00062
00063
00064
00065
00066 typeNode * idNode::base_type(bool TdefIndir) const
00067 {
00068 declNode * d = decl();
00069
00070 if (d)
00071 return d->type()->base_type(TdefIndir);
00072 else
00073 return (typeNode *)0;
00074 }
00075
00076 void idNode::decl(declNode * the_decl) {
00077 declNode * old_decl = _decl;
00078 _decl = the_decl;
00079 if ( old_decl )
00080 old_decl->ref_list().remove(this);
00081 if ( the_decl ) {
00082 the_decl->ref_list().push_back(this);
00083 the_decl->ref_list().sort();
00084 the_decl->ref_list().unique();
00085
00086 type((typeNode *) ref_clone_changer::clone(the_decl->type(), false));
00087 }
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 void idNode::eval()
00142 {
00143
00144
00145 declNode * ed = decl();
00146 if (ed && (ed->decl_location() == declNode::ENUM)) {
00147
00148
00149
00150 exprNode * e = ed->init();
00151 if (e) {
00152 e->eval();
00153 value(constant(e->value()));
00154 return;
00155 }
00156 }
00157
00158
00159
00160 value(constant());
00161 }
00162
00163
00164
00165
00166
00167 void idNode::visit(Visitor * the_visitor)
00168 {
00169 the_visitor->at_id(this);
00170 }
00171
00172 void idNode::walk(Walker & the_walker)
00173 {
00174 Walker::Order ord = the_walker.order();
00175
00176 if (ord == Walker::Preorder || ord == Walker::Both)
00177 the_walker.at_id(this, Walker::Preorder);
00178
00179 if (the_walker.depth() == Walker::Subtree) {
00180
00181
00182 if (type())
00183 type()->walk(the_walker);
00184 }
00185
00186 if (ord == Walker::Postorder || ord == Walker::Both)
00187 the_walker.at_id(this, Walker::Postorder);
00188 }
00189
00190
00191
00192
00193
00194 void idNode::dataflow(FlowVal * v, FlowProblem & fp)
00195 {
00196 if (fp.forward()) {
00197 fp.flow_id(v, this, FlowProblem::Entry);
00198 fp.flow_id(v, this, FlowProblem::Exit);
00199 }
00200 else {
00201 fp.flow_id(v, this, FlowProblem::Exit);
00202 fp.flow_id(v, this, FlowProblem::Entry);
00203 }
00204 }
00205
00206
00207
00208
00209
00210 void idNode::output_expr(output_context & ct, Node * parent, int prec, Assoc assoc)
00211 {
00212 bool par = parens(prec, assoc);
00213
00214 if (par)
00215 ct << '(';
00216
00217 ct << name();
00218
00219 if (par)
00220 ct << ')';
00221 }
00222
00223
00224
00225
00226
00227 Node * idNode::change(Changer & the_changer, bool redispatch)
00228 {
00229 Changer::Order ord = the_changer.order();
00230 idNode * the_id = this;
00231
00232 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00233 the_id = (idNode *) the_changer.at_id(the_id, Changer::Preorder);
00234
00235 if (the_id) {
00236
00237 if (the_id != this)
00238 return the_id->change(the_changer, true);
00239
00240 typeNode * old_type = the_id->type();
00241 if (old_type) {
00242 typeNode * new_type = (typeNode *) old_type->change(the_changer);
00243 if (old_type != new_type) {
00244
00245
00246 the_id->type(new_type);
00247 }
00248 }
00249
00250 }
00251
00252 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00253 the_id = (idNode *) the_changer.at_id(the_id, Changer::Postorder);
00254
00255 return the_id;
00256 }
00257
00258
00259
00260
00261
00262
00263 idNode::~idNode()
00264 {
00265 }