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  

vcg.cc

Go to the documentation of this file.
00001 // $Id: vcg.cc,v 1.5 2003/08/11 19:05:01 toktb Exp $
00002 
00003 // ----------------------------------------------------------------------
00004 //
00005 //  J-Breeze
00006 //  Java Compiler Framework
00007 // 
00008 //  Copyright (c) 2001 University of Texas at Austin
00009 // 
00010 //  Teck B. Tok
00011 //  Samuel Z. Guyer
00012 //  Daniel A. Jimenez
00013 //  Calvin Lin
00014 // 
00015 //  Permission is hereby granted, free of charge, to any person
00016 //  obtaining a copy of this software and associated documentation
00017 //  files (the "Software"), to deal in the Software without
00018 //  restriction, including without limitation the rights to use, copy,
00019 //  modify, merge, publish, distribute, and/or sublicense copies
00020 //  of the Software, and to permit persons to whom the Software is
00021 //  furnished to do so, subject to the following conditions:
00022 //  
00023 //  The above copyright notice and this permission notice shall be
00024 //  included in all copies or substantial portions of the Software.
00025 //  
00026 //  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027 //  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028 //  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029 //  NONINFRINGEMENT.  IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT
00030 //  AUSTIN BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
00031 //  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
00032 //  OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00033 //  THE SOFTWARE.
00034 //
00035 //  J-Breeze extends from C-Breeze (copyright University of Texas at
00036 //  Austin), part of whose design is inspired by the C-to-C Translator
00037 //  from MIT Laboratory for Computer Science.
00038 //
00039 // ----------------------------------------------------------------------
00040 
00041 #include "vcg.h"
00042 
00043 vcgWalker::vcgWalker(ostream& ostr, const string& comment,
00044                      string excludefilename)
00045   : Walker( Both, Subtree ), graph(ostr), currently_excluded(false) {
00046 #ifdef J_BREEZE
00047   current_type.clear();
00048 #endif
00049   exclude.clear();
00050 
00051   // Read the exclude file if present
00052   //char *excludefilename = getenv( "CALLG_EXCLUDE_FILE" );
00053   if( ! excludefilename.empty() ) {
00054     ifstream excludefile(excludefilename.c_str());
00055     if(! excludefile.is_open()) {
00056       cerr << "exclude file " << excludefilename << " cannot be opened\n";
00057       exit(1);
00058     } else {
00059       string name;
00060       while( excludefile >> name )
00061         exclude.push_back(name);
00062     }
00063   } //else cout << "no exclude file\n";
00064 
00065 } // constructor
00066 
00067 #ifdef J_BREEZE
00068 bool vcgWalker::excluded(typeNode *type) {
00069   if(!type || (type->typ()!=Class && type->typ()!=Interface)) return true;
00070   if(type->coord().line() == Coord::Unknown.line()) return true;
00071   string name = typenameNode::type_name(type);
00072   packageNode *p = packageNode::packageOf(type);
00073   string pname = p->fullname();
00074   string fullname = pname + "." + name;
00075 
00076   // search through list
00077   for(strings::iterator s=exclude.begin(); s!=exclude.end(); s++)
00078     if(*s==name || *s==pname || *s==fullname) return true;
00079   return false;
00080 } // excluded
00081 #else
00082 bool vcgWalker::excluded(procNode *proc) {
00083   string name = proc->decl()->name();
00084 
00085   // search through list
00086   return find(exclude.begin(), exclude.end(), name) != exclude.end();
00087 } // excluded
00088 
00089 bool vcgWalker::excluded(Coord coord) {
00090   if(coord.line() == Coord::Unknown.line()) return false;
00091   string filename = coord.filename();
00092 
00093   // search through list
00094   return find(exclude.begin(), exclude.end(), filename) != exclude.end();
00095 } // excluded
00096 #endif
00097 
00098 #ifdef J_BREEZE
00099 void vcgWalker::at_type(typeNode *type, Order order) {
00100   if(type->typ()!=Class && type->typ()!=Interface) return;
00101   if(order==Preorder) current_type.push_front(type);
00102   else                current_type.pop_front();
00103   if(current_type.empty())
00104     currently_excluded = true;
00105   else
00106     currently_excluded = excluded(current_type.front());
00107 } // at_type
00108 #else
00109 void vcgWalker::at_proc(procNode *proc, Order order) {
00110   if(order==Postorder) currently_excluded = false;
00111   else                 currently_excluded = excluded(proc);
00112 } // at_proc
00113 #endif
00114 
00115 void vcgWalker::print_comment(const string& comment) {
00116   graph << "// " << comment << endl; }
00117 
00118 void vcgWalker::print_graph_attribute(const string& attribute,
00119                                       const string& value) {
00120   graph << endl;
00121   graph << "   " << attribute << " : " << value << endl;
00122 }
00123 
00124 void vcgWalker::print_node_attribute(const string& attribute,
00125                                      const string& value) {
00126   graph << "\t" << attribute << ": \"" << value << "\"" << endl;
00127 }
00128 void vcgWalker::print_node_attribute(const string& attribute, int value) {
00129   graph << "\t" << attribute << ": " << value << endl;
00130 }
00131 
00132 void vcgWalker::print_node_value(const string& attribute, const string& value) {
00133   graph << "\t" << attribute << ": " << value << endl;
00134 }; // vcgWalker
00135 

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