backgroundparser.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <strstream>
00013
00014 #include "backgroundparser.h"
00015 #include "problemreporter.h"
00016 #include "PascalLexer.hpp"
00017 #include "PascalParser.hpp"
00018 #include "PascalAST.hpp"
00019 #include <kdebug.h>
00020 #include <qfile.h>
00021 #include <antlr/ASTFactory.hpp>
00022
00023 BackgroundParser::BackgroundParser( ProblemReporter* reporter,
00024 const QString& source,
00025 const QString& filename )
00026 : m_reporter( reporter ),
00027 m_source( source.unicode(), source.length() ),
00028 m_fileName( filename )
00029 {
00030 }
00031
00032 BackgroundParser::~BackgroundParser()
00033 {
00034 }
00035
00036 void BackgroundParser::run()
00037 {
00038 kdDebug() << "11" << endl;
00039
00040 QCString _fn = QFile::encodeName(m_fileName);
00041 std::string fn( _fn.data() );
00042
00043 QCString text = m_source.utf8();
00044 std::istrstream stream( text );
00045
00046 kdDebug() << "12" << endl;
00047
00048 PascalLexer lexer( stream );
00049 lexer.setFilename( fn );
00050 lexer.setProblemReporter( m_reporter );
00051
00052 kdDebug() << "13" << endl;
00053
00054 PascalParser parser( lexer );
00055 parser.setFilename( fn );
00056 parser.setProblemReporter( m_reporter );
00057
00058 antlr::ASTFactory my_factory( "PascalAST", PascalAST::factory );
00059 parser.initializeASTFactory(my_factory);
00060 parser.setASTFactory( &my_factory );
00061
00062 kdDebug() << "14" << endl;
00063
00064 try{
00065
00066 kdDebug() << "15" << endl;
00067
00068 lexer.resetErrors();
00069 parser.resetErrors();
00070
00071 kdDebug() << "16" << endl;
00072
00073 parser.compilationUnit();
00074
00075 kdDebug() << "17" << endl;
00076
00077 int errors = lexer.numberOfErrors() + parser.numberOfErrors();
00078
00079 kdDebug() << "18" << endl;
00080 } catch( antlr::ANTLRException& ex ){
00081
00082 kdDebug() << "19" << endl;
00083
00084 kdDebug() << "*exception*: " << ex.toString().c_str() << endl;
00085 m_reporter->reportError( ex.getMessage().c_str(),
00086 m_fileName,
00087 lexer.getLine(),
00088 lexer.getColumn() );
00089 }
00090
00091 kdDebug(9013) << "FINISHED!!" << endl;
00092 }
00093
00094
00095
This file is part of the documentation for KDevelop Version 3.1.2.