From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- languages/php/phpparser.cpp | 160 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 languages/php/phpparser.cpp (limited to 'languages/php/phpparser.cpp') diff --git a/languages/php/phpparser.cpp b/languages/php/phpparser.cpp new file mode 100644 index 00000000..b13c5479 --- /dev/null +++ b/languages/php/phpparser.cpp @@ -0,0 +1,160 @@ +/* + Copyright (C) 2005 by Nicolas Escuder + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + version 2, License as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "phpparser.h" +#include "phpsupportpart.h" +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#include "phpsupport_event.h" + +using namespace std; + +PHPParser::PHPParser(PHPSupportPart *part){ + m_part = part; + m_close = false; +} + +PHPParser::~PHPParser(){ + removeAllFiles(); +} + +bool PHPParser::hasFile( const QString& fileName ) +{ +// kdDebug(9018) << "hasFile " << fileName.latin1() << endl; + QString abso = URLUtil::canonicalPath(fileName); + QMap::Iterator it = m_files.find(abso); + + if ( it == m_files.end() ) + return false; + return true; +} + +void PHPParser::addFile( const QString& fileName ) +{ + QString abso = URLUtil::canonicalPath(fileName); + + if ( hasFile(abso) ) + return; + + kdDebug(9018) << "addFile " << fileName.latin1() << endl; + + QFileInfo fi( abso ); + if ((fi.extension().contains("inc") || fi.extension().contains("php") || fi.extension().contains("html") || fi.extension().contains("php3") || !fi.extension()) && !fi.extension().contains("~")) { + m_files.insert(abso, new PHPFile(m_part, abso)); + } +} + +void PHPParser::removeFile( const QString& fileName ) +{ +// kdDebug(9018) << "removeFile " << fileName.latin1() << endl; + QString abso = URLUtil::canonicalPath(fileName); + QMap::Iterator it = m_files.find(abso); + + if ( it != m_files.end()) { + PHPFile *file = it.data(); + m_files.remove( abso ); + delete( file ); + file = 0; + } +} + +void PHPParser::removeAllFiles() +{ + kdDebug(9018) << "removeAllFiles" << endl; + QMap::Iterator it = m_files.begin(); + + while( it != m_files.end() ){ + PHPFile * file = it.data(); + ++it; + delete( file ); + file = 0; + } + m_files.clear(); +} + +void PHPParser::reparseFile( const QString& fileName ) +{ + kdDebug(9018) << "reparseFile" << endl; + QString abso = URLUtil::canonicalPath(fileName); + QMap::Iterator it = m_files.find(abso); + + if ( it != m_files.end()) { + PHPFile *file = it.data(); + file->setModified(true); + file = 0; + } + m_canParse.wakeAll(); +} + +void PHPParser::run() { + kdDebug(9018) << "run thread " << QThread::currentThread() << endl; + QMap::Iterator it; + + while ( !m_close ) { + m_canParse.wait(); + + if ( m_close ) + break; + + it = m_files.begin(); + + while( it != m_files.end() ){ + PHPFile * file = it.data(); + if (!m_close) { + if ( file->isModified() ) { + file->Analyse(); + it = m_files.begin(); + } else { + ++it; + } + file = 0; + } else { + it = m_files.end(); + } + } + } +} + +void PHPParser::close() +{ + kdDebug(9018) << "closing thread" << endl; + m_close = true; + m_canParse.wakeAll(); + + while (running()) { + kapp->processEvents(); + } +} + +void PHPParser::startParse() { + kdDebug(9018) << "startParse" << endl; + m_canParse.wakeAll(); +} -- cgit v1.2.1