backgroundparser.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 * Copyright (C) 2002 by Roberto Raggi * 00003 * roberto@kdevelop.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "backgroundparser.h" 00013 #include "problemreporter.h" 00014 #include "AdaLexer.hpp" 00015 #include "AdaParser.hpp" 00016 #include "AdaAST.hpp" 00017 #include <kdebug.h> 00018 #include <qfile.h> 00019 00020 #include <config.h> 00021 00022 #ifdef HAVE_SSTREAM 00023 #include <sstream> 00024 #else 00025 #include <strstream.h> 00026 #endif 00027 00028 BackgroundParser::BackgroundParser( ProblemReporter* reporter, 00029 const QString& source, 00030 const QString& filename ) 00031 : m_reporter( reporter ), 00032 m_source( source.unicode(), source.length() ), 00033 m_fileName( filename ) 00034 { 00035 } 00036 00037 BackgroundParser::~BackgroundParser() 00038 { 00039 } 00040 00041 void BackgroundParser::run() 00042 { 00043 QCString _fn = QFile::encodeName(m_fileName); 00044 std::string fn( _fn.data() ); 00045 00046 #ifdef HAVE_SSTREAM 00047 std::istringstream stream( m_source.utf8().data() ); 00048 #else 00049 istrstream stream( m_source.utf8().data() ); 00050 #endif 00051 00052 AdaLexer lexer( stream ); 00053 lexer.setFilename( fn ); 00054 lexer.setProblemReporter( m_reporter ); 00055 00056 AdaParser parser( lexer ); 00057 parser.setFilename( fn ); 00058 parser.setProblemReporter( m_reporter ); 00059 00060 // make an ast factory 00061 antlr::ASTFactory ast_factory; 00062 // initialize and put it in the parser... 00063 parser.initializeASTFactory (ast_factory); 00064 parser.setASTFactory (&ast_factory); 00065 // parser.setASTNodeType ("RefAdaAST"); 00066 00067 try{ 00068 lexer.resetErrors(); 00069 parser.resetErrors(); 00070 00071 parser.compilation_unit(); 00072 00073 } catch( antlr::ANTLRException& ex ){ 00074 kdDebug() << "*exception*: " << ex.toString().c_str() << endl; 00075 m_reporter->reportError( QString::fromLatin1( ex.getMessage().c_str() ), 00076 m_fileName, 00077 lexer.getLine(), 00078 lexer.getColumn() ); 00079 } 00080 00081 kdDebug() << "BackgroundParser::run() FINISHED." << endl; 00082 } 00083 00084 00085