|
||
output_context.hGo to the documentation of this file.00001 // $Id: output_context.h,v 1.5 2003/08/07 23:14:03 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 #ifndef CBZ_OUTPUT_CONTEXT_H 00039 #define CBZ_OUTPUT_CONTEXT_H 00040 00041 #include <set> 00042 00043 typedef set<suespecNode *> ssn_set; 00044 00045 typedef list< int > int_list; 00046 typedef int_list::iterator int_list_p; 00047 00048 class output_context 00049 { 00050 private: 00051 00052 ostream & _out; 00053 int _pos; 00054 int _line; 00055 00056 int_list _parens; 00057 00058 // -- Maintain statement depth 00059 00060 int _depth; 00061 00062 // -- Remember the last output character 00063 00064 char _last; 00065 00066 // pnav 00067 // set to remember output suespecNodes 00068 ssn_set _ssNodes; 00069 00070 // -- Internal new-line function 00071 00072 void _new_line(); 00073 00074 // -- Print some spaces 00075 00076 void _indent(const int num); 00077 00078 public: 00079 00080 output_context(ostream & out) 00081 : _out(out), 00082 _pos(0), 00083 _line(0), 00084 _parens(), 00085 _depth(0), 00086 _last('\n'), 00087 _ssNodes() 00088 {} 00089 00090 // -- Output operators 00091 00092 output_context & operator<<(const string & s); 00093 output_context & operator<<(const char * s); 00094 00095 // -- IMPORTANT: this operator controls indenting information so 00096 // it's important to always output delimiters using it. 00097 00098 output_context & operator<<(const char c); 00099 00100 // -- Handle statement boundaries.. 00101 00102 void indent_in() { ++_depth; } 00103 void indent_out() { --_depth; } 00104 00105 // -- Start a new line anywhere 00106 00107 void new_line(); 00108 00109 // -- Continue a line that was getting too long 00110 00111 void continue_line(); 00112 00113 // -- Add a space, if necessary (based on the last character) 00114 00115 void space(); 00116 00117 // -- Return the current line position 00118 00119 int pos() const { return _pos; } 00120 00121 // pnav 00122 // remember a suespecNode so it is not printed again 00123 void printed(suespecNode * ssn); 00124 00125 // pnav 00126 // return whether a suespecNode has been printed 00127 bool isPrinted(suespecNode * ssn); 00128 00129 // -- Width for line-wrapping... 00130 00131 static int wrap_width; 00132 00133 }; 00134 00135 00136 #endif // CBZ_OUTPUT_CONTEXT_H |
Generated on August 27, 2003
Back to the C-Breeze home page