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  

initializernode.cc

Go to the documentation of this file.
00001 // $Id: initializernode.cc,v 1.3 2003/08/07 23:13:07 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 
00040 // --------------------------------------------------------------------
00041 // Constructors
00042 // --------------------------------------------------------------------
00043 
00044 initializerNode::initializerNode(expr_list * exprs, const Coord coord)
00045   : exprNode(Initializer, 0, coord),
00046     _exprs()
00047 {
00048   if (exprs) {
00049     _exprs.swap(* exprs);
00050     //delete exprs;
00051   }
00052 }
00053 
00054 // ------------------------------------------------------------
00055 // Expression evaluator
00056 // ------------------------------------------------------------
00057 
00058 void initializerNode::eval()
00059 {
00060   // -- Evaluate all the subexpressions
00061 
00062   for (expr_list_p p = exprs().begin();
00063        p != exprs().end();
00064        ++p)
00065     {
00066       (*p)->eval();
00067     }
00068 
00069   // -- This really shouldn't have a value
00070 
00071   value(constant());
00072 }
00073 
00074 // ------------------------------------------------------------
00075 //  Walker
00076 // ------------------------------------------------------------
00077 
00078 void initializerNode::visit(Visitor * the_visitor) 
00079 {
00080   the_visitor->at_initializer(this);
00081 }
00082 
00083 void initializerNode::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_initializer(this, Walker::Preorder);
00089 
00090   if (the_walker.depth() == Walker::Subtree) {
00091     // -- Visit the children 
00092 
00093     list_walker(exprs(), the_walker);
00094 
00095     if (type())
00096       type()->walk(the_walker);
00097   }
00098 
00099   if (ord == Walker::Postorder || ord == Walker::Both)
00100     the_walker.at_initializer(this, Walker::Postorder);
00101 }
00102 
00103 // ------------------------------------------------------------
00104 //  Dataflow
00105 // ------------------------------------------------------------
00106 
00107 void initializerNode::dataflow(FlowVal * v, FlowProblem & fp)
00108 {
00109   if (fp.forward()) {
00110     fp.flow_initializer(v, this, FlowProblem::Entry);
00111 
00112     dataflow_forward_list(exprs(), v, fp);
00113 
00114     fp.flow_initializer(v, this, FlowProblem::Exit);
00115   }
00116   else {
00117     fp.flow_initializer(v, this, FlowProblem::Exit);
00118 
00119     dataflow_reverse_list(exprs(), v, fp);
00120 
00121     fp.flow_initializer(v, this, FlowProblem::Entry);
00122   }
00123 }
00124 
00125 // ------------------------------------------------------------
00126 // Output
00127 // ------------------------------------------------------------
00128 
00129 void initializerNode::output_expr(output_context & ct, Node * parent, int prec, Assoc assoc)
00130 {
00131   bool par = parens(prec, assoc);
00132 
00133   if (par)
00134     ct << '(';
00135 
00136   ct.indent_in();
00137   ct.new_line();
00138   ct << '{';
00139   ct.space();
00140 
00141   output_delim_list(exprs(), ct, this, ',');
00142 
00143   ct.indent_out();
00144   ct.space();
00145   ct << '}';
00146 
00147   if (par)
00148     ct << ')';
00149 }
00150 
00151 // ------------------------------------------------------------
00152 //  Changer
00153 // ------------------------------------------------------------
00154 
00155 Node * initializerNode::change(Changer & the_changer, bool redispatch)
00156 {
00157   Changer::Order ord = the_changer.order(); 
00158   initializerNode * the_initializer = this;
00159 
00160   if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00161     the_initializer = (initializerNode *) the_changer.at_initializer(the_initializer, Changer::Preorder);
00162 
00163   if (the_initializer) {
00164 
00165     if (the_initializer != this)
00166       return the_initializer->change(the_changer, true);
00167 
00168     change_list(the_initializer->exprs(), the_changer);
00169 
00170     typeNode * old_type = the_initializer->type();
00171     if (old_type) {
00172       typeNode * new_type = (typeNode *) old_type->change(the_changer);
00173       if (old_type != new_type) {
00174         //if (the_changer.delete_old())
00175           //delete old_type;
00176         the_initializer->type(new_type);
00177       }
00178     }
00179 
00180   }
00181 
00182   if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00183     the_initializer = (initializerNode *) the_changer.at_initializer(the_initializer, Changer::Postorder);
00184 
00185   return the_initializer;
00186 }
00187 
00188 
00189 // ------------------------------------------------------------
00190 // Destructor
00191 // ------------------------------------------------------------
00192 
00193 initializerNode::~initializerNode()
00194 {
00195   //delete_list(_exprs);
00196 }

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