C-Breeze
C Compiler Infrastructure

[ Project home page]
Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

meta.cc

Go to the documentation of this file.
00001 // $Id: meta.cc,v 1.4 2003/08/07 23:13:33 pnav Exp $
00002 // ----------------------------------------------------------------------
00003 //
00004 //  C-Breeze
00005 //  C Compiler Framework
00006 // 
00007 //  Copyright (c) 2000 University of Texas at Austin
00008 // 
00009 //  Samuel Z. Guyer
00010 //  Daniel A. Jimenez
00011 //  Calvin Lin
00012 // 
00013 //  Permission is hereby granted, free of charge, to any person
00014 //  obtaining a copy of this software and associated documentation
00015 //  files (the "Software"), to deal in the Software without
00016 //  restriction, including without limitation the rights to use, copy,
00017 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00018 //  of the Software, and to permit persons to whom the Software is
00019 //  furnished to do so, subject to the following conditions:
00020 //  
00021 //  The above copyright notice and this permission notice shall be
00022 //  included in all copies or substantial portions of the Software.
00023 //  
00024 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00028 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00029 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00030 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00031 //  THE SOFTWARE.
00032 //
00033 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00034 //  Computer Science for inspiring parts of the C-Breeze design.
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     // -- Visit the children 
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         //if (the_changer.delete_old())
00105           //delete old_type;
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 // -- Dataflow
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 // -- Output
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 // -- Walk and change
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     // -- Visit the children 
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 // -- Dataflow
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 // -- Output 
00226 void 
00227 metastmtNode::output_stmt(output_context & ct, Node * par)
00228 {
00229   ct << name() << ':';
00230   //????
00231   ct << ';';
00232 }

Generated on August 27, 2003
Back to the C-Breeze home page