PreprocessorCache Class Reference

#include <preprocessorcontrol.h>

Inheritance diagram for PreprocessorCache:

Inheritance graph
[legend]
Collaboration diagram for PreprocessorCache:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 50 of file preprocessorcontrol.h.

Signals

void error (QString type, QString text)
void readFile (QByteArray &contents, QString filename)

Public Member Functions

 PreprocessorCache ()
TokenEngine::TokenContainer sourceTokens (const QString &filename)
Rpp::SourcesourceTree (const QString &filename)
bool containsSourceTokens (const QString &filename)
bool containsSourceTree (const QString &filename)

Private Member Functions

QByteArray readFile (const QString &filename) const

Private Attributes

Tokenizer m_tokenizer
Rpp::RppLexer m_lexer
Rpp::Preprocessor m_preprocessor
TypedPool< Rpp::Itemm_memoryPool
QHash< QString, Rpp::Source * > m_sourceTrees
QHash< QString, TokenEngine::TokenContainerm_sourceTokens


Constructor & Destructor Documentation

PreprocessorCache::PreprocessorCache (  ) 

Definition at line 150 of file preprocessorcontrol.cpp.

References QObject::connect(), error(), m_preprocessor, and SIGNAL.

00151 {
00152     connect(&m_preprocessor, SIGNAL(error(QString,QString)),
00153             this, SIGNAL(error(QString,QString)));
00154 }

Here is the call graph for this function:


Member Function Documentation

TokenContainer PreprocessorCache::sourceTokens ( const QString filename  ) 

Definition at line 164 of file preprocessorcontrol.cpp.

References QHash< Key, T >::contains(), TokenEngine::FileInfo::filename, QHash< Key, T >::insert(), m_sourceTokens, m_tokenizer, readFile(), Tokenizer::tokenize(), and QHash< Key, T >::value().

Referenced by ProjectPorter::enableAttributes(), FilePorter::port(), and sourceTree().

00165 {
00166     // Check if the source tokens are already in the cache.
00167     if(m_sourceTokens.contains(filename))
00168         return m_sourceTokens.value(filename);
00169 
00170     // Read and tokenize file.
00171     QByteArray fileContents = readFile(filename);
00172     if(fileContents == QByteArray())
00173         return TokenContainer();
00174 
00175     QVector<TokenEngine::Token> tokenList = m_tokenizer.tokenize(fileContents);
00176 
00177     // Create a FileInfo object that holds the filename for this container.
00178     FileInfo *containterFileInfo = new FileInfo;
00179     containterFileInfo->filename = filename;
00180 
00181     // Create container.
00182     TokenContainer tokenContainer(fileContents, tokenList, containterFileInfo);
00183 
00184     // Insert into cache.
00185     m_sourceTokens.insert(filename, tokenContainer);
00186     return tokenContainer;
00187 }

Here is the call graph for this function:

Source * PreprocessorCache::sourceTree ( const QString filename  ) 

Definition at line 196 of file preprocessorcontrol.cpp.

References QHash< Key, T >::contains(), TokenEngine::TokenContainer::count(), QHash< Key, T >::insert(), Rpp::RppLexer::lex(), m_lexer, m_memoryPool, m_preprocessor, m_sourceTrees, Rpp::Preprocessor::parse(), Rpp::Source::setFileName(), sourceTokens(), and QHash< Key, T >::value().

Referenced by PreprocessorController::evaluate(), and FilePorter::port().

00197 {
00198     // Check if the Rpp tree for this file is already in the cache.
00199     if(m_sourceTrees.contains(filename))
00200         return m_sourceTrees.value(filename);
00201 
00202     // Get the tokens for the contents of this file.
00203     TokenContainer tokenContainer = sourceTokens(filename);
00204 
00205     // Run lexer and the preprocessor-parser.
00206     QVector<Type> tokenTypes = m_lexer.lex(tokenContainer);
00207     Source *source = m_preprocessor.parse(tokenContainer, tokenTypes, &m_memoryPool);
00208     source->setFileName(filename);
00209 
00210     // Insert into cache.
00211     if(tokenContainer.count() > 0) //don't cache empty files.
00212         m_sourceTrees.insert(filename, source);
00213 
00214     return source;
00215 }

Here is the call graph for this function:

bool PreprocessorCache::containsSourceTokens ( const QString filename  ) 

Definition at line 221 of file preprocessorcontrol.cpp.

References QHash< Key, T >::contains(), and m_sourceTokens.

00222 {
00223     return m_sourceTokens.contains(filename);
00224 }

Here is the call graph for this function:

bool PreprocessorCache::containsSourceTree ( const QString filename  ) 

Definition at line 229 of file preprocessorcontrol.cpp.

References QHash< Key, T >::contains(), and m_sourceTrees.

00230 {
00231     return m_sourceTrees.contains(filename);
00232 }

Here is the call graph for this function:

void PreprocessorCache::error ( QString  type,
QString  text 
) [signal]

Referenced by PreprocessorCache().

void PreprocessorCache::readFile ( QByteArray contents,
QString  filename 
) [signal]

Referenced by readFile(), and sourceTokens().

QByteArray PreprocessorCache::readFile ( const QString filename  )  const [private]

Definition at line 129 of file preprocessorcontrol.cpp.

References emit, QFile::exists(), QIODevice::isOpen(), QFile::open(), QIODevice::readAll(), readFile(), QIODevice::ReadOnly, QObject::receivers(), and SIGNAL.

00130 {
00131     // If anybody is connected to the readFile signal we tell them to
00132     // read the file for us.
00133     if (receivers(SIGNAL(readFile(QByteArray&,QString))) > 0) {
00134         QByteArray array;
00135         // Workaround for "not beeing able to emit from const function"
00136         PreprocessorCache *cache = const_cast<PreprocessorCache *>(this);
00137         emit cache->readFile(array, filename);
00138         return array;
00139     }
00140 
00141     QFile f(filename);
00142     if (!f.exists())
00143         return QByteArray();
00144     f.open(QIODevice::ReadOnly);
00145     if (!f.isOpen())
00146         return QByteArray();
00147     return f.readAll();
00148 }

Here is the call graph for this function:


Member Data Documentation

Tokenizer PreprocessorCache::m_tokenizer [private]

Definition at line 64 of file preprocessorcontrol.h.

Referenced by sourceTokens().

Rpp::RppLexer PreprocessorCache::m_lexer [private]

Definition at line 65 of file preprocessorcontrol.h.

Referenced by sourceTree().

Rpp::Preprocessor PreprocessorCache::m_preprocessor [private]

Definition at line 66 of file preprocessorcontrol.h.

Referenced by PreprocessorCache(), and sourceTree().

TypedPool<Rpp::Item> PreprocessorCache::m_memoryPool [private]

Definition at line 67 of file preprocessorcontrol.h.

Referenced by sourceTree().

QHash<QString, Rpp::Source *> PreprocessorCache::m_sourceTrees [private]

Definition at line 68 of file preprocessorcontrol.h.

Referenced by containsSourceTree(), and sourceTree().

QHash<QString, TokenEngine::TokenContainer> PreprocessorCache::m_sourceTokens [private]

Definition at line 69 of file preprocessorcontrol.h.

Referenced by containsSourceTokens(), and sourceTokens().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:36:08 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1