diff --git a/parsejob.cpp b/parsejob.cpp index 45b50d5..d0d35f0 100644 --- a/parsejob.cpp +++ b/parsejob.cpp @@ -1,182 +1,182 @@ /* This file is part of KDevelop * * Copyright 2008-2010 Alexander Dymo * Copyright 2011 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* TODO: Clean This mess */ #include "parsejob.h" #include #include #include #include #include "Thread.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "rubylanguagesupport.h" // #include "parser/parser.h" #include // #include #include "duchain/declarationbuilder.h" #include "duchain/editorintegrator.h" using namespace KDevelop; namespace Ruby { ParseJob::ParseJob(const KUrl & url, RubyLanguageSupport * parent) : KDevelop::ParseJob(url) , m_parser (new RubyParser) - , m_url (url) , m_lastAst(NULL) { - /* There's nothing to do here */ + m_parent = parent; + m_url = url; } ParseJob::~ParseJob() { /* There's nothing to do here */ } RubyLanguageSupport * ParseJob::ruby() const { return RubyLanguageSupport::self(); } void ParseJob::run() { //Happens during shutdown if (!ruby()) return abortJob(); if (abortRequested()) return abortJob(); KDevelop::UrlParseLock urlLock(document()); { DUChainReadLocker lock(DUChain::lock()); bool needsUpdate = true; static const IndexedString langString("Ruby"); foreach(const ParsingEnvironmentFilePointer & file, DUChain::self()->allEnvironmentFiles(document())) { if (file->language() != langString) continue; if (file->needsUpdate()) { needsUpdate = true; break; } else needsUpdate = false; } if (!(minimumFeatures() & TopDUContext::ForceUpdate || minimumFeatures() & Resheduled) && !needsUpdate) { kDebug() << "Already up to date" << document().str(); return; } } KDevelop::ProblemPointer p = readContents(); if (p) return abortJob(); /* TODO: ToUtf ?¿ */ QString cont = contents().contents; if (abortRequested()) return abortJob(); m_parser->setCurrentDocument(m_url); QReadLocker parseLock(ruby()->language()->parseLock()); parse(); if ( abortRequested() ) return abortJob(); } void ParseJob::parse() { m_parser->freeAst(m_lastAst); /* TODO: It may go after the builder */ m_lastAst = m_parser->parse(); if (m_lastAst != NULL) { kDebug() << "Everything is fine " << m_lastAst->tree->kind << endl; } else { kDebug() << "Failed\n"; foreach (ProblemPointer p, m_parser->m_problems) { kDebug() << p->range(); kDebug() << p->description(); } } // KDevelop::ReferencedTopDUContext top; // { // KDevelop::DUChainReadLocker lock(KDevelop::DUChain::lock()); // top = KDevelop::DUChain::self()->chainForDocument(document()); // } // if (top) { // kDebug() << "re-compiling" << document().str(); // KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock()); // top->clearImportedParentContexts(); // top->parsingEnvironmentFile()->clearModificationRevisions(); // top->clearProblems(); // } else // kDebug() << "compiling" << document().str(); // // QReadLocker parseLock(ruby()->language()->parseLock()); // // EditorIntegrator editor; // editor.setUrl(document()); // DeclarationBuilder builder; // builder.setEditor(&editor); // top = builder.build(document(), programAST, top); // delete programAST; // // setDuChain(top); // // KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock()); // // top->setFeatures(minimumFeatures()); // KDevelop::ParsingEnvironmentFilePointer file = top->parsingEnvironmentFile(); // // file->setModificationRevision(contents().modification); // KDevelop::DUChain::self()->updateContextEnvironment( top->topContext(), file.data() ); } } // end of namespace ruby #include "parsejob.moc" diff --git a/parsejob.h b/parsejob.h index c93e90b..0393015 100644 --- a/parsejob.h +++ b/parsejob.h @@ -1,65 +1,87 @@ /* This file is part of KDevelop * * Copyright 2008-2010 Alexander Dymo * Copyright (C) 2011 Miquel Sabaté * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef RUBY_PARSEJOB_H #define RUBY_PARSEJOB_H #include #include #include + class RubyLanguageSupport; namespace Ruby { class RubyParser; class ParseJob : public KDevelop::ParseJob { Q_OBJECT public: - enum { - Resheduled = KDevelop::TopDUContext::LastFeature - }; - - ParseJob( const KUrl &url, RubyLanguageSupport* parent ); - + enum { Resheduled = KDevelop::TopDUContext::LastFeature }; + + /** + * Constructor. + * + * @param url the url of the file to parse. + * @param parent the RubyLanguageSupport this ParseJob is parented to. + */ + ParseJob(const KUrl & url, RubyLanguageSupport * parent); + + /** + * Destructor. + */ virtual ~ParseJob(); + /** + * @return static accessor to avoid casting. + */ RubyLanguageSupport * ruby() const; protected: + /** + * Runs this ParseJob. + */ virtual void run(); private: + /** + * @internal Called by the run() method. It's used to do the + * parsing magic. + */ void parse(); +private: + const RubyLanguageSupport * m_parent; KUrl m_url; RubyParser * m_parser; RubyAst * m_lastAst; }; } // end of namespace ruby + #endif +