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  

conditiongotonode.cc

Go to the documentation of this file.
00001 // $Id: conditiongotonode.cc,v 1.3 2003/08/07 23:13:02 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 //  Adam Brown
00013 // 
00014 //  Permission is hereby granted, free of charge, to any person
00015 //  obtaining a copy of this software and associated documentation
00016 //  files (the "Software"), to deal in the Software without
00017 //  restriction, including without limitation the rights to use, copy,
00018 //  modify, merge, publish, distribute, sublicense, and/or sell copies
00019 //  of the Software, and to permit persons to whom the Software is
00020 //  furnished to do so, subject to the following conditions:
00021 //  
00022 //  The above copyright notice and this permission notice shall be
00023 //  included in all copies or substantial portions of the Software.
00024 //  
00025 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00026 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00027 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00028 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00029 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00030 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00031 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00032 //  THE SOFTWARE.
00033 //
00034 //  We acknowledge the C-to-C Translator from MIT Laboratory for
00035 //  Computer Science for inspiring parts of the C-Breeze design.
00036 //
00037 // ----------------------------------------------------------------------
00038 
00039 #include "c_breeze.h"
00040 
00041 // ------------------------------------------------------------
00042 // Constructors
00043 // ------------------------------------------------------------
00044 
00045 conditiongotoNode::conditiongotoNode(labelNode * label, indexNode * left, 
00046                                      unsigned int op_id, indexNode * right, 
00047                                      const Coord coord):
00048   gotoNode(label, coord, Condition),
00049   _oper1(left),
00050   _oper2(right)
00051 {
00052   Operator * new_op = Operators::table[op_id];
00053   op(new_op);
00054 }
00055 
00056 // ------------------------------------------------------------
00057 // Data access & modification
00058 // ------------------------------------------------------------
00059 
00060 void conditiongotoNode::op(Operator * op) {
00061   if ( op->is_comparison() )
00062     _op = op;
00063   else
00064     // TODO: throw an exception?
00065     ;
00066 }
00067 
00068 // ------------------------------------------------------------
00069 // Walker
00070 // ------------------------------------------------------------
00071 
00072 void conditiongotoNode::visit(Visitor * the_visitor)
00073 {
00074   the_visitor->at_conditiongoto(this);
00075 }
00076 
00077 void conditiongotoNode::walk(Walker & the_walker)
00078 {
00079   Walker::Order ord = the_walker.order();
00080 
00081   if ( ord == Walker::Preorder || ord == Walker::Both )
00082     the_walker.at_conditiongoto(this, Walker::Preorder);
00083 
00084   if ( the_walker.depth() == Walker::Subtree ) {
00085     // -- Visit the children
00086 
00087     left()->walk(the_walker);
00088     right()->walk(the_walker);
00089   }
00090 
00091   if ( ord == Walker::Postorder || ord == Walker::Both )
00092     the_walker.at_conditiongoto(this, Walker::Postorder);
00093 }
00094 
00095 // ------------------------------------------------------------
00096 // Changer
00097 // ------------------------------------------------------------
00098 
00099 Node * conditiongotoNode::change(Changer & the_changer, bool redispatch)
00100 {
00101   Changer::Order ord = the_changer.order();
00102   conditiongotoNode * the_condgoto = this;
00103 
00104   if ( ( ord == Changer::Preorder || ord == Changer::Both ) && !redispatch )
00105     the_condgoto = 
00106       (conditiongotoNode *) the_changer.at_conditiongoto(the_condgoto,
00107                                                          Changer::Preorder);
00108   
00109   if ( the_condgoto ) {
00110     if ( the_condgoto != this )
00111       return the_condgoto->change(the_changer, true);
00112     
00113     indexNode * old_left = the_condgoto->left();
00114     indexNode * new_left = (indexNode *) old_left->change(the_changer);
00115     if ( old_left != new_left )
00116       the_condgoto->left(new_left);
00117     
00118     indexNode * old_right = the_condgoto->right();
00119     indexNode * new_right = (indexNode *) old_right->change(the_changer);
00120     if ( old_right != new_right )
00121       the_condgoto->right(new_right);
00122   }
00123 
00124   if ( ( ord == Changer::Postorder || ord == Changer::Both ) && !redispatch)
00125     the_condgoto = 
00126       (conditiongotoNode *) the_changer.at_conditiongoto(the_condgoto,
00127                                                          Changer::Postorder);
00128 
00129   return the_condgoto;
00130 }
00131 
00132 // ------------------------------------------------------------
00133 // Output
00134 // ------------------------------------------------------------
00135 
00136 void conditiongotoNode::output_stmt(output_context & ct, Node * parent) 
00137 {
00138   ct << "if";
00139   ct.space();
00140   ct << '(' ;
00141   ct.space();
00142 
00143   left()->output(ct, this);
00144   ct.space();
00145   ct << op()->print();
00146   ct.space();
00147   right()->output(ct, this);
00148 
00149   ct << ')';
00150   ct.space();
00151 
00152   gotoNode::output_stmt(ct, parent);
00153 }
00154 
00155 // ------------------------------------------------------------
00156 // Dataflow
00157 // ------------------------------------------------------------
00158 
00159 void conditiongotoNode::dataflow(FlowVal * v, FlowProblem & fp)
00160 {
00161   // TODO:  uhhh, sam?
00162 }

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