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 #include "changer.h"
00041 #include "ref_clone_changer.h"
00042
00043
00044
00045
00046
00047 subdeclNode::subdeclNode(declNode * orig, int index)
00048 : declNode(*orig),
00049 _original(orig),
00050 _index(index)
00051
00052 {
00053 if (type())
00054 type((typeNode *) ref_clone_changer::clone(type(), false));
00055
00056 init(0);
00057 bitsize(0);
00058 attrib_list().clear();
00059 }
00060
00061
00062
00063
00064
00065 string subdeclNode::name_with_index()
00066 {
00067 ostringstream ost;
00068
00069 ost << name() << '@' << index();
00070
00071 return ost.str();
00072 }
00073
00074
00075
00076
00077
00078 void subdeclNode::visit(Visitor * the_visitor)
00079 {
00080 the_visitor->at_subdecl(this);
00081 }
00082
00083 void subdeclNode::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_subdecl(this, Walker::Preorder);
00089
00090 if (the_walker.depth() == Walker::Subtree) {
00091
00092
00093 if (type())
00094 type()->walk(the_walker);
00095
00096 if (init())
00097 init()->walk(the_walker);
00098
00099 if (bitsize())
00100 bitsize()->walk(the_walker);
00101
00102 list_walker(attribs(), the_walker);
00103 }
00104
00105 if (ord == Walker::Postorder || ord == Walker::Both)
00106 the_walker.at_subdecl(this, Walker::Postorder);
00107 }
00108
00109
00110
00111
00112
00113 void subdeclNode::output(output_context & ct, Node * parent)
00114 {
00115 Decl_location loc = decl_location();
00116
00117 if (loc == ENUM)
00118 ct << name();
00119 else {
00120
00121 if (loc != FORMAL)
00122 ct.new_line();
00123
00124 ct << storage_class_name(storage_class());
00125 ct.space();
00126
00127 type()->output_type(ct, this, Left, typeNode::NONE);
00128
00129 if (! name().empty()) {
00130 ct.space();
00131 ct << name_with_index();
00132 }
00133
00134 type()->output_type(ct, this, Right, typeNode::NONE);
00135 }
00136
00137 if (init()) {
00138 ct.space();
00139 ct << '=';
00140 ct.space();
00141 init()->output(ct, this);
00142 }
00143
00144 if (bitsize()) {
00145 ct.space();
00146 ct << ':';
00147 ct.space();
00148 bitsize()->output(ct, this);
00149 }
00150
00151 if ((loc == TOP) ||
00152 (loc == BLOCK) ||
00153 (loc == SU) ||
00154 (loc == UNKNOWN) )
00155 ct << ';';
00156 }
00157
00158
00159
00160
00161
00162 Node * subdeclNode::change(Changer & the_changer, bool redispatch)
00163 {
00164 Changer::Order ord = the_changer.order();
00165 subdeclNode * the_subdecl = this;
00166
00167 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00168 the_subdecl = (subdeclNode *) the_changer.at_subdecl(the_subdecl, Changer::Preorder);
00169
00170 if (the_subdecl) {
00171
00172 if (the_subdecl != this)
00173 return the_subdecl->change(the_changer, true);
00174
00175 typeNode * old_type = the_subdecl->type();
00176 if (old_type) {
00177 typeNode * new_type = (typeNode *) old_type->change(the_changer);
00178 if (old_type != new_type) {
00179 if (the_changer.delete_old())
00180 delete old_type;
00181 the_subdecl->type(new_type);
00182 }
00183 }
00184
00185 exprNode * old_init = the_subdecl->init();
00186 if (old_init) {
00187 exprNode * new_init = (exprNode *) old_init->change(the_changer);
00188 if (old_init != new_init) {
00189 if (the_changer.delete_old())
00190 delete old_init;
00191 the_subdecl->init(new_init);
00192 }
00193 }
00194
00195 exprNode * old_bitsize = the_subdecl->bitsize();
00196 if (old_bitsize) {
00197 exprNode * new_bitsize = (exprNode *) old_bitsize->change(the_changer);
00198 if (old_bitsize != new_bitsize) {
00199 if (the_changer.delete_old())
00200 delete old_bitsize;
00201 the_subdecl->bitsize(new_bitsize);
00202 }
00203 }
00204
00205 change_list(the_subdecl->attribs(), the_changer);
00206
00207 }
00208
00209 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00210 the_subdecl = (subdeclNode *) the_changer.at_subdecl(the_subdecl, Changer::Postorder);
00211
00212 return the_subdecl;
00213 }
00214
00215
00216
00217
00218
00219 subdeclNode::~subdeclNode()
00220 {
00221 }