Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

writer.cc

Go to the documentation of this file.
00001 /*
00002  *  File:       writer.cc
00003  *              $Id: writer.cc,v 1.3 2002/06/13 11:43:29 alec Exp $
00004  *
00005  *  Author:     Alec Panoviciu (alecu@email.com)
00006  *
00007  *  Comments:
00008  *
00009  *  Revision history:
00010  *
00011  *  $Log: writer.cc,v $
00012  *  Revision 1.3  2002/06/13 11:43:29  alec
00013  *  added #line stuff
00014  *
00015  *  Revision 1.2  2002/05/16 22:11:21  alec
00016  *  sync
00017  *
00018  *  Revision 1.1  2002/05/04 17:46:53  alec
00019  *  *** empty log message ***
00020  *
00021  */
00022 
00023 /* 
00024   Copyright (C) 2002 Alexandru Panoviciu (alecu@email.com)
00025 
00026   This program is free software; you can redistribute it and/or modify
00027   it under the terms of the GNU General Public License as published by
00028   the Free Software Foundation; either version 2 of the License, or
00029   (at your option) any later version.
00030 
00031   This program is distributed in the hope that it will be useful,
00032   but WITHOUT ANY WARRANTY; without even the implied warranty of
00033   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00034   GNU General Public License for more details.
00035 
00036   You should have received a copy of the GNU General Public License
00037   along with this program; if not, write to the Free Software
00038   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00039 
00040  */
00041 
00042 #include <cctype>
00043 #include <algorithm>
00044 
00045 #include "parse_util.hh"
00046 #include "prop_registry.hh"
00047 #include "writer.hh"
00048 
00049 
00050 string Writer::className2cc (const string &className)
00051 {
00052   string res;
00053 
00054   for (int n = 0; n < className.size(); n++)
00055     if (isupper(className[n])) {
00056       if (n != 0) res += '_';
00057       res += tolower(className[n]);
00058     } else res += className[n];
00059   
00060   if (registry.contains("cc_extension"))
00061     return (res += '.') += registry["cc_extension"];
00062   else 
00063     return res += ".cc";
00064 }
00065 
00066 
00067 string Writer::className2hh (const string &className)
00068 {
00069   string res;
00070 
00071   for (int n = 0; n < className.size(); n++)
00072     if (isupper(className[n])) {
00073       if (n != 0) res += '_';
00074       res += tolower(className[n]);
00075     } else res += className[n];
00076 
00077   if (registry.contains("hh_extension"))
00078     return (res += '.') += registry["hh_extension"];
00079   else 
00080     return res += ".hh";
00081 }
00082 
00083 string Writer::className2macro (const string &className)
00084 {
00085   string res("__");
00086 
00087   for (int n = 0; n < className.size(); n++)
00088     if (isupper(className[n])) {
00089       if (n != 0) res += '_';
00090       res += className[n];
00091     } else res += toupper(className[n]);
00092 
00093   return res += "_HH__";
00094 }
00095 
00096 
00097 string Writer::fullPath (const string &fileName)
00098 {
00099   if (registry.contains("target_dir"))
00100     return ((string) registry["target_dir"]) + fileName;
00101   else return fileName;
00102 }
00103 
00104 
00105 void Writer::openStream (const string &fullPathName)
00106 {
00107   ofs.open(fullPathName.c_str());
00108   if (!ofs)
00109     die(string("Could not open file \"") + fullPathName + "\" for writing.");
00110 
00111   _indent.resize(0);
00112   _line = 8;
00113   _file = fullPathName;
00114   
00115   ofs << "/******************************************************************"
00116       << endl
00117       << " * File: " << fullPathName << endl
00118       << " *" << endl
00119       << " * This file was automatically generated by CppCC Version " << VERSION
00120       << endl
00121       << " * DO NOT EDIT MANUALLY" << endl
00122       << " ******************************************************************/"
00123       << endl
00124       << endl;
00125 }
00126 
00127 
00128 void Writer::closeStream ()
00129 {
00130   ofs << endl << endl << endl
00131       << "/* End of file. */"
00132       << endl; //add an extra newline (gcc seems to want this)
00133   ofs.close();
00134 }
00135 
00136 
00137 ostream& Writer::writeChunk (const CodeChunk &cc, const string &terminator)
00138 {
00139   if (registry["SHARP_LINES"]) {
00140     int lines = cc.countLines();
00141     // the stored position (at least when dealing with YACC & LEX) will be
00142     // the one corresponding to the end of the chunk of code (due to the fact
00143     // that we used the value of yylineno after we parsed the chunk
00144     ofs << endl << "#line " << cc.pos.ln - lines + 1
00145         << " \"" << registry["input_file"]
00146         << "\"" << endl;
00147     _line += 2;
00148     ofs << cc.code << terminator;
00149     _line += lines + 1;
00150     ofs << endl << "#line " << _line << " \"" << _file << "\"" << endl;
00151   } else {
00152     ofs << cc.code << terminator << endl;
00153     _line += cc.countLines() + 1;
00154   }
00155   return ofs;
00156 }

Generated at Tue Jul 9 21:05:46 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001