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 "meta.h"
00040
00041
00042 list< string > metaexprNode::meta_expr_variables;
00043 list< string > metastmtNode::meta_stmt_variables;
00044
00045 bool metaexprNode::is_meta_expr(char * name)
00046 {
00047 list<string>::iterator i = find(meta_expr_variables.begin(), meta_expr_variables.end(), string(name));
00048 return(i != meta_expr_variables.end());
00049 }
00050
00051 void metaexprNode::add_meta_expr(char * name)
00052 {
00053 meta_expr_variables.push_back(string(name));
00054 }
00055
00056 void metaexprNode::clear()
00057 {
00058 meta_expr_variables.clear();
00059 }
00060
00061 void
00062 metaexprNode::visit(Visitor * the_visitor)
00063 {
00064 the_visitor->at_expr(this);
00065 }
00066
00067 void
00068 metaexprNode::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_expr(this, Walker::Preorder);
00074
00075 if (the_walker.depth() == Walker::Subtree) {
00076
00077
00078 if (type())
00079 type()->walk(the_walker);
00080 }
00081
00082 if (ord == Walker::Postorder || ord == Walker::Both)
00083 the_walker.at_expr(this, Walker::Postorder);
00084 }
00085
00086 Node *
00087 metaexprNode::change(Changer & the_changer, bool redispatch = false)
00088 {
00089 Changer::Order ord = the_changer.order();
00090 exprNode * the_en = this;
00091
00092 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00093 the_en = (exprNode *) the_changer.at_expr(the_en, Changer::Preorder);
00094
00095 if (the_en) {
00096
00097 if (the_en != this)
00098 return the_en->change(the_changer, true);
00099
00100 typeNode * old_type = the_en->type();
00101 if (old_type) {
00102 typeNode * new_type = (typeNode *) old_type->change(the_changer);
00103 if (old_type != new_type) {
00104
00105
00106 the_en->type(new_type);
00107 }
00108 }
00109
00110 }
00111
00112 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00113 the_en = (exprNode *) the_changer.at_expr(the_en, Changer::Postorder);
00114
00115 return the_en;
00116 }
00117
00118
00119 void
00120 metaexprNode::dataflow(FlowVal * v, FlowProblem & fp)
00121 {
00122 if (fp.forward()) {
00123 fp.flow_expr(v, this, FlowProblem::Entry);
00124 fp.flow_expr(v, this, FlowProblem::Exit);
00125 }
00126 else {
00127 fp.flow_expr(v, this, FlowProblem::Exit);
00128 fp.flow_expr(v, this, FlowProblem::Entry);
00129 }
00130 }
00131
00132
00133
00134 void
00135 metaexprNode::output_expr(output_context & ct, Node * par, int prec, Assoc assoc)
00136 {
00137 bool p = parens(prec, assoc);
00138
00139 if (p)
00140 ct << '(';
00141
00142 ct << name();
00143
00144 if (p)
00145 ct << ')';
00146 }
00147
00148 bool metastmtNode::is_meta_stmt(char * name)
00149 {
00150 list<string>::iterator i = find(meta_stmt_variables.begin(), meta_stmt_variables.end(), string(name));
00151 return(i != meta_stmt_variables.end());
00152 }
00153
00154 void metastmtNode::add_meta_stmt(char * name)
00155 {
00156 meta_stmt_variables.push_back(string(name));
00157 }
00158
00159 void metastmtNode::clear()
00160 {
00161 meta_stmt_variables.clear();
00162 }
00163
00164
00165
00166 void
00167 metastmtNode::visit(Visitor * the_visitor)
00168 {
00169 the_visitor->at_stmt(this);
00170 }
00171
00172 void
00173 metastmtNode::walk(Walker & the_walker)
00174 {
00175 Walker::Order ord = the_walker.order();
00176
00177 if (ord == Walker::Preorder || ord == Walker::Both)
00178 the_walker.at_stmt(this, Walker::Preorder);
00179
00180 if (the_walker.depth() == Walker::Subtree) {
00181
00182 }
00183
00184 if (ord == Walker::Postorder || ord == Walker::Both)
00185 the_walker.at_stmt(this, Walker::Postorder);
00186 }
00187
00188 Node *
00189 metastmtNode::change(Changer & the_changer, bool redispatch)
00190 {
00191 Changer::Order ord = the_changer.order();
00192 stmtNode * the_stmt = this;
00193
00194 if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00195 the_stmt = (stmtNode *) the_changer.at_stmt(the_stmt, Changer::Preorder);
00196
00197 if (the_stmt) {
00198
00199 if (the_stmt != this)
00200 return the_stmt->change(the_changer, true);
00201
00202 }
00203
00204 if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00205 the_stmt = (labelNode *) the_changer.at_stmt(the_stmt, Changer::Postorder);
00206
00207 return the_stmt;
00208 }
00209
00210
00211
00212 void
00213 metastmtNode::dataflow(FlowVal * v, FlowProblem & fp)
00214 {
00215 if (fp.forward()) {
00216 fp.flow_stmt(v, this, FlowProblem::Entry);
00217 fp.flow_stmt(v, this, FlowProblem::Exit);
00218 }
00219 else {
00220 fp.flow_stmt(v, this, FlowProblem::Exit);
00221 fp.flow_stmt(v, this, FlowProblem::Entry);
00222 }
00223 }
00224
00225
00226 void
00227 metastmtNode::output_stmt(output_context & ct, Node * par)
00228 {
00229 ct << name() << ':';
00230
00231 ct << ';';
00232 }