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  

node.cc

Go to the documentation of this file.
00001 // $Id: node.cc,v 1.5 2003/08/07 23:13:09 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 int ncount = 0;
00039 int freqs[100];
00040 static void print_all (void);
00041 
00042 #include "c_breeze.h"
00043 
00044 // -- These are for tracking memory leaks...
00045 
00046 int Node::_count = 0;
00047 int Node::_uid_count = 0;
00048 int Node::_t_count[50];
00049 
00050 char * TypNames[] = {
00051   // expression nodes
00052   "Const", "Id", "Binary", "Unary", "Cast", "Comma", "Ternary",
00053   "Call", "Initializer",
00054 
00055   // statement nodes 
00056   "Label", "Switch", "Case", "If", "While", "Do",
00057   "For", "Goto", "Continue", "Break", "Return", "Block", 
00058 
00059   // type nodes 
00060   "Prim", "Tdef", "Ptr", "Array", "Func", "Struct", "Union", "Enum", "sueSpec",
00061 
00062 
00063   // declaration node 
00064   "Decl", 
00065 
00066   // GCC __attribute__ extension 
00067   "Attrib", 
00068 
00069   // procedure def node
00070   "Proc",
00071 
00072   // random text and preprocessor command node
00073   "Text",
00074 
00075   // A statement that just consists of an expression
00076   "Expr",
00077 
00078   // Special undeclared node
00079   "Undeclared",
00080 
00081   // Translation unit
00082 
00083   "Unit"
00084 };
00085 
00086 // --------------------------------------------------------------------
00087 // Constructors
00088 // --------------------------------------------------------------------
00089 
00090 Node::Node(NodeType the_typ, const Coord coord, bool parenthesized)
00091   : _typ(the_typ), 
00092     _coord(coord), 
00093     _parenthesized(parenthesized),
00094     _annotations(),
00095     _gen(0),
00096     _kill(0)
00097 {
00098 /*
00099 if (ncount == 0) {
00100 for (int i=0; i<100; i++) freqs[i] = 0;
00101 }
00102 ncount++;
00103 if (ncount % 1000 == 0) print_all ();
00104 freqs[_typ]++;
00105 */
00106   Node::nodes.push_back (this);
00107   ++_count;
00108   ++_t_count[the_typ];
00109   //  ++_uid_count;
00110   // _uid = _uid_count;
00111 }
00112 
00113 // static map of all nodes, used for garbage collection
00114 
00115 node_list Node::nodes;
00116 map <Node *, bool> Node::deleted_nodes;
00117 
00118 static void print_all (void) {
00119 int     i;
00120 
00121 printf ("node freqs:\n");
00122 for (i=0; i<100; i++) if (freqs[i]) printf ("%d: %d\n", i, freqs[i]);
00123 }
00124 Node::Node(const Node & other)
00125   : _typ(other._typ), 
00126     _coord(other._coord), 
00127     _parenthesized(other._parenthesized),
00128     _annotations(),
00129     _gen(0),
00130     _kill(0)
00131 {
00132 /*  if (ncount == 0) {
00133 for (int i=0; i<100; i++) freqs[i] = 0;
00134 }
00135 ncount++;
00136 if (ncount % 1000 == 0) print_all ();
00137 freqs[_typ]++;
00138 */
00139   Node::nodes.push_back (this);
00140   // ++_count;
00141   // ++_t_count[other._typ];
00142   // ++_uid_count;
00143   // _uid = _uid_count;
00144 }
00145 
00146 // ------------------------------------------------------------
00147 //  Data type base
00148 // ------------------------------------------------------------
00149 
00150 // -- Each node implements it's own version of base_type()
00151 
00152 typeNode * Node::base_type(bool TdefIndir) const
00153 {
00154   return (typeNode *) 0;
00155 }
00156 
00157 typeNode * Node::datatype() const
00158 { 
00159   return base_type(true);
00160 }
00161 
00162 typeNode * Node::datatype_superior() const
00163 {
00164   return base_type(false);
00165 }
00166 
00167 
00168 // ------------------------------------------------------------
00169 // Destructor
00170 // ------------------------------------------------------------
00171 
00172 Node::~Node()
00173 {
00174   deleted_nodes[this] = true;
00175   //delete_list(_annotations);
00176   // --_t_count[_typ];
00177   // --_count;
00178 }
00179 
00180 // ------------------------------------------------------------
00181 // Report memory usage
00182 // ------------------------------------------------------------
00183 
00184 void Node::report()
00185 {
00186   cout << "Nodes: " << _count << endl;
00187   for (int i = 0; i <= Undeclared; ++i) {
00188     if (_t_count[i] != 0) {
00189 
00190       cout << "  ";
00191       switch (i) {
00192       case Const:
00193         cout << "Const";
00194         break;
00195       case Id:
00196         cout << "Id";
00197         break;
00198       case Binary:
00199         cout << "Binary";
00200         break;
00201       case Unary:
00202         cout << "Unary";
00203         break;
00204       case Cast:
00205         cout << "Cast";
00206         break;
00207       case Comma:
00208         cout << "Comma";
00209         break;
00210       case Ternary:
00211         cout << "Ternary";
00212         break;
00213       case Call:
00214         cout << "Call";
00215         break;
00216       case Initializer:
00217         cout << "Initializer";
00218         break;
00219       case Label:
00220         cout << "Label";
00221         break;
00222       case Switch:
00223         cout << "Switch";
00224         break;
00225       case Case:
00226         cout << "Case";
00227         break;
00228       case If:
00229         cout << "If";
00230         break;
00231       case While:
00232         cout << "While";
00233         break;
00234       case Do:
00235         cout << "Do";
00236         break;
00237       case For:
00238         cout << "For";
00239         break;
00240       case Goto:
00241         cout << "Goto";
00242         break;
00243       case Continue:
00244         cout << "Continue";
00245         break;
00246       case Break:
00247         cout << "Break";
00248         break;
00249       case Return:
00250         cout << "Return";
00251         break;
00252       case Block:
00253         cout << "Block";
00254         break;
00255       case Prim:
00256         cout << "Prim";
00257         break;
00258       case Tdef:
00259         cout << "Tdef";
00260         break;
00261       case Ptr:
00262         cout << "Ptr";
00263         break;
00264       case Array:
00265         cout << "Array";
00266         break;
00267       case Func:
00268         cout << "Func";
00269         break;
00270       case Struct:
00271         cout << "Struct";
00272         break;
00273       case Union:
00274         cout << "Union";
00275         break;
00276       case Enum:
00277         cout << "Enum";
00278         break;
00279       case sueSpec:
00280         cout << "sueSpec";
00281         break;
00282       case Decl:
00283         cout << "Decl";
00284         break;
00285       case Attrib:
00286         cout << "Attrib";
00287         break;
00288       case Proc:
00289         cout << "Proc";
00290         break;
00291       case Text:
00292         cout << "Text";
00293         break;
00294       case Expr:
00295         cout << "Expr";
00296         break;
00297       case Undeclared:
00298         cout << "Undeclared";
00299         break;
00300       default:
00301         cout << "ERROR";
00302         break;
00303       }
00304 
00305       cout << " : " << _t_count[i] << endl;
00306     }
00307   }
00308 }

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