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  

subdeclnode.cc

Go to the documentation of this file.
00001 // $Id: subdeclnode.cc,v 1.6 2003/08/07 23:13:12 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 #include "changer.h"
00041 #include "ref_clone_changer.h"
00042 
00043 // --------------------------------------------------------------------
00044 // Constructors
00045 // --------------------------------------------------------------------
00046 
00047 subdeclNode::subdeclNode(declNode * orig, int index)
00048   : declNode(*orig),
00049     _original(orig),
00050     _index(index)
00051 
00052 {
00053   if (type())
00054     type((typeNode *) ref_clone_changer::clone(type(), false));
00055 
00056   init(0);
00057   bitsize(0);
00058   attrib_list().clear();
00059 }
00060 
00061 // ------------------------------------------------------------
00062 // Fields
00063 // ------------------------------------------------------------
00064 
00065 string subdeclNode::name_with_index()
00066 {
00067   ostringstream ost;
00068 
00069   ost << name() << '@' << index();
00070 
00071   return ost.str();
00072 }
00073 
00074 // ------------------------------------------------------------
00075 //  Walker
00076 // ------------------------------------------------------------
00077 
00078 void subdeclNode::visit(Visitor * the_visitor) 
00079 {
00080   the_visitor->at_subdecl(this);
00081 }
00082 
00083 void subdeclNode::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_subdecl(this, Walker::Preorder);
00089 
00090   if (the_walker.depth() == Walker::Subtree) {
00091     // -- Visit the children 
00092 
00093     if (type())
00094       type()->walk(the_walker);
00095 
00096     if (init())
00097       init()->walk(the_walker);
00098 
00099     if (bitsize())
00100       bitsize()->walk(the_walker);
00101 
00102     list_walker(attribs(), the_walker);
00103   }
00104 
00105   if (ord == Walker::Postorder || ord == Walker::Both)
00106     the_walker.at_subdecl(this, Walker::Postorder);
00107 }
00108 
00109 // ------------------------------------------------------------
00110 // Ouput
00111 // ------------------------------------------------------------
00112 
00113 void subdeclNode::output(output_context & ct, Node * parent)
00114 {
00115   Decl_location loc = decl_location();
00116 
00117   if (loc == ENUM)
00118     ct << name();
00119   else {
00120 
00121     if (loc != FORMAL)
00122       ct.new_line();
00123 
00124     ct << storage_class_name(storage_class());
00125     ct.space();
00126 
00127     type()->output_type(ct, this, Left, typeNode::NONE);
00128 
00129     if (! name().empty()) {
00130       ct.space();
00131       ct << name_with_index();
00132     }
00133 
00134     type()->output_type(ct, this, Right, typeNode::NONE);
00135   }
00136 
00137   if (init()) {
00138     ct.space();
00139     ct << '=';
00140     ct.space();
00141     init()->output(ct, this);
00142   }
00143 
00144   if (bitsize()) {
00145     ct.space();
00146     ct << ':';
00147     ct.space();
00148     bitsize()->output(ct, this);
00149   }
00150 
00151   if ((loc == TOP) ||
00152       (loc == BLOCK) ||
00153       (loc == SU) ||
00154       (loc == UNKNOWN) )
00155     ct << ';';
00156 }
00157 
00158 // ------------------------------------------------------------
00159 //  Changer
00160 // ------------------------------------------------------------
00161 
00162 Node * subdeclNode::change(Changer & the_changer, bool redispatch)
00163 {
00164   Changer::Order ord = the_changer.order(); 
00165   subdeclNode * the_subdecl = this;
00166 
00167   if ((ord == Changer::Preorder || ord == Changer::Both) && ! redispatch)
00168     the_subdecl = (subdeclNode *) the_changer.at_subdecl(the_subdecl, Changer::Preorder);
00169 
00170   if (the_subdecl) {
00171 
00172     if (the_subdecl != this)
00173       return the_subdecl->change(the_changer, true);
00174 
00175     typeNode * old_type = the_subdecl->type();
00176     if (old_type) {
00177       typeNode * new_type = (typeNode *) old_type->change(the_changer);
00178       if (old_type != new_type) {
00179         if (the_changer.delete_old())
00180           delete old_type;
00181         the_subdecl->type(new_type);
00182       }
00183     }
00184 
00185     exprNode * old_init = the_subdecl->init();
00186     if (old_init) {
00187       exprNode * new_init = (exprNode *) old_init->change(the_changer);
00188       if (old_init != new_init) {
00189         if (the_changer.delete_old())
00190           delete old_init;
00191         the_subdecl->init(new_init);
00192       }
00193     }
00194 
00195     exprNode * old_bitsize = the_subdecl->bitsize();
00196     if (old_bitsize) {
00197       exprNode * new_bitsize = (exprNode *) old_bitsize->change(the_changer);
00198       if (old_bitsize != new_bitsize) {
00199         if (the_changer.delete_old())
00200           delete old_bitsize;
00201         the_subdecl->bitsize(new_bitsize);
00202       }
00203     }
00204 
00205     change_list(the_subdecl->attribs(), the_changer);
00206 
00207   }
00208 
00209   if ((ord == Changer::Postorder || ord == Changer::Both) && ! redispatch)
00210     the_subdecl = (subdeclNode *) the_changer.at_subdecl(the_subdecl, Changer::Postorder);
00211 
00212   return the_subdecl;
00213 }
00214 
00215 // ------------------------------------------------------------
00216 // Destructor
00217 // ------------------------------------------------------------
00218 
00219 subdeclNode::~subdeclNode()
00220 {
00221 }

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