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

Writer Class Reference

#include <writer.hh>

Inheritance diagram for Writer:

Inheritance graph
[legend]
Collaboration diagram for Writer:

Collaboration graph
[legend]
List of all members.

Protected Methods

 Writer (PropRegistry &registry_)
string className2cc (const string &className)
string className2hh (const string &className)
string className2macro (const string &className)
string fullPath (const string &fileName)
void openStream (const string &fullPathName)
void closeStream ()
void indent ()
void unindent ()
ostream& line (bool dumpSharpLine=false)
ostream& writeChunk (const CodeChunk &cc, const string &terminator="")

Protected Attributes

ofstream ofs
PropRegistryregistry

Private Attributes

int _line
string _file
string _indent

Detailed Description

This is the superclass opf all the classes that actually write some sources. It defines things like how the code should be _indented, how to generate a filename from a class name, what extensions to use, etc.

The following registry keys are used, if found:

Definition at line 77 of file writer.hh.


Constructor & Destructor Documentation

Writer::Writer ( PropRegistry & registry_ ) [inline, protected]
 

Definition at line 81 of file writer.hh.


Member Function Documentation

string Writer::className2cc ( const string & className ) [protected]
 

Returns the name of the .cc file for a certain class name. By default, given a ClassNameLikeThis, it returns class_name_like_this.cc

Definition at line 50 of file writer.cc.

Referenced by LaParserWriter::writeParser(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

string Writer::className2hh ( const string & className ) [protected]
 

Returns the name of the .hh file for a certain class name. By default, given a ClassNameLikeThis, it returns class_name_like_this.hh

Definition at line 67 of file writer.cc.

Referenced by LaParserWriter::writeParser(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

string Writer::className2macro ( const string & className ) [protected]
 

Returns a string suitable for use in an ifndef multiple inclusino avoidance directive.

Definition at line 83 of file writer.cc.

Referenced by LaParserWriter::writeParser(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

string Writer::fullPath ( const string & fileName ) [protected]
 

Returns the full path for a certain file name, that is the result of appending the file's name to the given destination directory where files should be put, if any.

Definition at line 97 of file writer.cc.

Referenced by LaParserWriter::writeParser(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

void Writer::openStream ( const string & fullPathName ) [protected]
 

tries to open ofs for writing with the given file name. If it succedes, it also writes the "this file was generated by CppCC blah blah" starting comment into the file. If the open fails, it die()s.

Additionally, it resetes the _indent level (just in case it was left in a messy state frmo a previous file:).

Definition at line 105 of file writer.cc.

Referenced by LaParserWriter::writeParser(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

void Writer::closeStream ( ) [protected]
 

Closes the ofs strem, after adding an ending comment at the end fo the currently open file.

Definition at line 128 of file writer.cc.

Referenced by LaParserWriter::writeParser(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

void Writer::indent ( ) [inline, protected]
 

Definition at line 126 of file writer.hh.

Referenced by LaEpDefWriter::operator()(), LaParserWriter::writeEbnf(), LaParserWriter::writeEbnfLa(), LaParserWriter::writeLaDefs(), LaParserWriter::writeParser(), LaParserWriter::writeProductionDefs(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

void Writer::unindent ( ) [inline, protected]
 

Definition at line 131 of file writer.hh.

Referenced by LaEpDefWriter::operator()(), LaParserWriter::writeEbnf(), LaParserWriter::writeEbnfLa(), LaParserWriter::writeLaDefs(), LaParserWriter::writeParser(), LaParserWriter::writeProductionDefs(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

ostream & Writer::line ( bool dumpSharpLine = false ) [inline, protected]
 

Definition at line 137 of file writer.hh.

Referenced by LaEpDefWriter::operator()(), LaEpDeclWriter::operator()(), LaParserWriter::writeEbnf(), LaParserWriter::writeEbnfLa(), LaParserWriter::writeLaDefs(), LaParserWriter::writeLaEpDecls(), LaParserWriter::writeParser(), LaParserWriter::writeProductionDecls(), LaParserWriter::writeProductionDefs(), LaParserWriter::writeProductionLaDecls(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().

ostream & Writer::writeChunk ( const CodeChunk & cc,
const string & terminator = "" ) [protected]
 

This method must be used or writing usercode stored in CodeChunk objects. If used consusently together with line() for normal output, it is able to dump the correct line directives (if the SHARP_LINES option is activated). For this the method relies on line() to be the only point where a new line is ever dumped into the output stream. At the end of the usercode chunk it will also append the terminator string (if any is given), BEFORE the line directive that switches back to the actual .cc file (this is because gcc seems to only report errors locations when it reaches the next token after the error's place, which may be already in the .ccalthough the error is from a usercode chunk). Of course, the terminator must not contain any newline characters.

Definition at line 137 of file writer.cc.

Referenced by LaParserWriter::makeLaCondition(), LaParserWriter::writeEbnf(), LaParserWriter::writeEbnfLa(), LaParserWriter::writeParser(), LaParserWriter::writeProductionDecls(), LaParserWriter::writeProductionDefs(), ScannerDfaWriter::writeScanner(), and TokenWriter::writeTokenClass().


Member Data Documentation

ofstream Writer::ofs [protected]
 

The stream into which this writer dumps the data. We had to place it here (and not in derived classes) because it must be known to the line() method.

Definition at line 167 of file writer.hh.

PropRegistry & Writer::registry [protected]
 

Definition at line 169 of file writer.hh.

int Writer::_line [private]
 

Definition at line 174 of file writer.hh.

string Writer::_file [private]
 

Definition at line 175 of file writer.hh.

string Writer::_indent [private]
 

This string defines our current _indentation level.

Definition at line 180 of file writer.hh.


The documentation for this class was generated from the following files:
Generated at Tue Jul 9 21:08:56 2002 for CppCC by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001