1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include "CxxUsingNamespaceCollector.h"
#include "CxxScannerTokens.h"
#include "CxxPreProcessor.h"
CxxUsingNamespaceCollector::CxxUsingNamespaceCollector(CxxPreProcessor* preProcessor, const wxFileName& filename)
: CxxScannerBase(preProcessor, filename)
{
}
CxxUsingNamespaceCollector::~CxxUsingNamespaceCollector() {}
void CxxUsingNamespaceCollector::OnToken(CxxLexerToken& token)
{
switch(token.type) {
case T_PP_INCLUDE_FILENAME: {
// we found an include statement, recurse into it
wxFileName include;
if(m_preProcessor->CanGoDeeper() && m_preProcessor->ExpandInclude(m_filename, token.text, include)) {
CxxUsingNamespaceCollector* scanner = new CxxUsingNamespaceCollector(m_preProcessor, include);
m_preProcessor->IncDepth();
scanner->Parse();
m_preProcessor->DecDepth();
// Append the matched results to the current parser results
m_usingNamespaces.insert(
m_usingNamespaces.end(), scanner->GetUsingNamespaces().begin(), scanner->GetUsingNamespaces().end());
wxDELETE(scanner);
DEBUGMSG("<== Resuming parser on file: %s\n", m_filename.GetFullPath());
}
break;
}
case T_USING:
ParseUsingNamespace();
break;
default:
break;
}
}
void CxxUsingNamespaceCollector::ParseUsingNamespace()
{
// Get the next token
CxxLexerToken token;
if(!::LexerNext(m_scanner, token)) return;
if(token.type != T_NAMESPACE) return;
// Read everything until we find the ';'
wxString usingNamespace;
while(::LexerNext(m_scanner, token)) {
if(token.type == ';') {
break;
}
usingNamespace << token.text;
}
if(!usingNamespace.IsEmpty()) {
m_usingNamespaces.Add(usingNamespace);
}
}
|