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  

commanode.cc

Go to the documentation of this file.
00001 // $Id: commanode.cc,v 1.3 2003/08/07 23:13:01 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 commaNode::commaNode(expr_list * exprs, const Coord coord)
00045   : exprNode(Comma, 0, coord),
00046     _exprs()
00047 {
00048   if (exprs) {
00049     _exprs.swap(* exprs);
00050     //delete exprs;
00051   }
00052 }
00053 
00054 commaNode::commaNode(const Coord coord)
00055   : exprNode(Comma, 0, coord),
00056     _exprs()
00057 {}
00058 
00059 // ------------------------------------------------------------
00060 // Data type base
00061 // ------------------------------------------------------------
00062 
00063 typeNode * commaNode::base_type(bool TdefIndir) const
00064 {
00065   const expr_list & the_exprs = exprs();
00066  
00067   // -- The type of a comma expr is the type of the last expr in the
00068   // list.
00069 
00070  if (! the_exprs.empty())
00071     return the_exprs.back()->base_type(TdefIndir);
00072  else
00073    return (typeNode *)0;
00074 }
00075 
00076 // ------------------------------------------------------------
00077 // Operator precedence
00078 // ------------------------------------------------------------
00079 
00080 int commaNode::precedence(Assoc & assoc)
00081 {
00082   assoc = Left;
00083   return 1;
00084 }
00085 
00086 // ------------------------------------------------------------
00087 // Expression evaluator
00088 // ------------------------------------------------------------
00089 
00090 void commaNode::eval()
00091 {
00092   // -- Evaluate all the subexpressions
00093 
00094   for (expr_list_p p = exprs().begin();
00095        p != exprs().end();
00096        ++p)
00097     {
00098       (*p)->eval();
00099     }
00100 
00101   // -- The value of the comma is the value of the last expr
00102 
00103   value(exprs().back()->value());
00104 }
00105 
00106 // ------------------------------------------------------------
00107 //  Walker
00108 // ------------------------------------------------------------
00109 
00110 void commaNode::visit(Visitor * the_visitor) 
00111 {
00112   the_visitor->at_comma(this);
00113 }
00114 
00115 void commaNode::walk(Walker & the_walker)
00116 {
00117   Walker::Order ord = the_walker.order(); 
00118 
00119   if (ord == Walker::Preorder || ord == Walker::Both)
00120     the_walker.at_comma(this, Walker::Preorder);
00121 
00122   if (the_walker.depth() == Walker::Subtree) {
00123     // -- Visit the children 
00124 
00125     list_walker(exprs(), the_walker);
00126 
00127     if (type())
00128       type()->walk(the_walker);
00129   }
00130 
00131   if (ord == Walker::Postorder || ord == Walker::Both)
00132     the_walker.at_comma(this, Walker::Postorder);
00133 }
00134 
00135 // ------------------------------------------------------------
00136 //  Dataflow
00137 // ------------------------------------------------------------
00138 
00139 void commaNode::dataflow(FlowVal * v, FlowProblem & fp)
00140 {
00141   if (fp.forward()) {
00142     fp.flow_comma(v, this, FlowProblem::Entry);
00143 
00144     dataflow_forward_list(exprs(), v, fp);
00145 
00146     fp.flow_comma(v, this, FlowProblem::Exit);
00147   }
00148   else {
00149     fp.flow_comma(v, this, FlowProblem::Exit);
00150 
00151     dataflow_reverse_list(exprs(), v, fp);
00152 
00153     fp.flow_comma(v, this, FlowProblem::Entry);
00154   }
00155 }
00156 
00157 // ------------------------------------------------------------
00158 // Output
00159 // ------------------------------------------------------------
00160 
00161 void commaNode::output_expr(output_context & ct, Node * parent, int prec, Assoc assoc)
00162 {
00163   bool par = parens(prec, assoc);
00164   int myprec;
00165   Assoc myassoc;
00166 
00167   myprec = precedence(myassoc);
00168 
00169   if (par)
00170     ct << '(';
00171 
00172   output_delim_list(exprs(), ct, this, ',');
00173 
00174   if (par)
00175     ct << ')';
00176 }
00177 
00178 // ------------------------------------------------------------
00179 //  Changer
00180 // ------------------------------------------------------------
00181 
00182 Node * commaNode::change(Changer & the_changer, bool redispatch)
00183 {
00184   Changer::Order ord = the_changer.order(); 
00185   commaNode * the_comma = this;
00186 
00187   if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00188     the_comma = (commaNode *) the_changer.at_comma(the_comma, Changer::Preorder);
00189 
00190   if (the_comma) {
00191 
00192     if (the_comma != this)
00193       return the_comma->change(the_changer, true);
00194 
00195     change_list(the_comma->exprs(), the_changer);
00196 
00197     typeNode * old_type = the_comma->type();
00198     if (old_type) {
00199       typeNode * new_type = (typeNode *) old_type->change(the_changer);
00200       if (old_type != new_type) {
00201         //if (the_changer.delete_old())
00202          // delete old_type;
00203         the_comma->type(new_type);
00204       }
00205     }
00206 
00207   }
00208 
00209   if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00210     the_comma = (commaNode *) the_changer.at_comma(the_comma, Changer::Postorder);
00211 
00212   return the_comma;
00213 }
00214 
00215 
00216 // ------------------------------------------------------------
00217 // Destructor
00218 // ------------------------------------------------------------
00219 
00220 commaNode::~commaNode()
00221 {
00222   //delete_list(_exprs);
00223 }

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