1
/***************************************************************************
2
* Copyright 2008 Aleix Pol <aleixpol@gmail.com> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU Library General Public License as *
6
* published by the Free Software Foundation; either version 2 of the *
7
* License, or (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU Library General Public *
15
* License along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18
***************************************************************************/
20
#include "duchainextractor.h"
21
#include <interfaces/ilanguage.h>
22
#include <interfaces/ilanguagecontroller.h>
23
#include <interfaces/iplugin.h>
24
#include <interfaces/iplugincontroller.h>
25
#include <language/interfaces/ilanguagesupport.h>
26
#include <language/duchain/duchain.h>
27
#include <language/duchain/dumpchain.h>
28
#include <language/duchain/topducontext.h>
29
#include <language/duchain/declaration.h>
30
#include <language/duchain/duchainlock.h>
31
#include <language/backgroundparser/backgroundparser.h>
32
#include <shell/projectcontroller.h>
33
#include <shell/core.h>
34
#include "krosswrapper.h"
35
#include "krossimpl.h"
37
#include "duchainreader.h"
39
#include <QApplication>
42
using namespace KDevelop;
44
class KrossInterfaceCreator : public DUChainReader
47
KrossInterfaceCreator(TopDUContext* top) : DUChainReader(top) {}
48
virtual void writeDocument() { qDebug() << "start doc"; }
49
virtual void writeClass(const QString& classname, const QString& , const QList<QStringList>& )
50
{ qDebug() << "start class" << classname; }
51
virtual void writeNamespace(const QString& name) { qDebug() << "start namespace" << name; }
52
virtual void writeVariable(const QString& name, const QString& type, bool isConst)
53
{ qDebug() << "start var" << name << type << isConst; }
54
virtual void writeEndClass() { qDebug() << "end class"; }
55
virtual void writeEndDocument() { qDebug() << "end doc"; }
56
virtual void writeEndFunction(const method& m)
59
foreach(const method::argument& arg, m.args)
60
{ args+= arg.type+' '+arg.name+'='+arg.def; }
61
qDebug() << "end func" << m.returnType << m.funcname << args.join(", ");
63
virtual void writeEndEnum(const QStringList& flags) { qDebug() << "start enum" << flags; }
67
DUChainExtractor::DUChainExtractor(QObject* parent) : QObject(parent), m_done(false)
69
connect(Core::self()->languageController()->backgroundParser(), SIGNAL(parseJobFinished(KDevelop::ParseJob*)),
70
this, SLOT(parsingFinished(KDevelop::ParseJob*)));
73
void DUChainExtractor::start(const KUrl& _input, const KUrl& builddir,
74
const KUrl::List& includes, const QString& filename,
75
const QString& directory, const QStringList& toinclude, const QString& output)
79
m_directory=directory;
80
m_toinclude=toinclude;
83
m_manager = new DummyBSM(0, QVariantList(), KUrl::List() << _input);
84
m_manager->setBuildDir(builddir);
85
m_manager->setIncludeDirectories(includes);
86
DumbProject* project = new DumbProject();
87
project->setManagerPlugin(m_manager);
88
Core::self()->projectControllerInternal()->addProject(project);
89
Core::self()->languageController()->backgroundParser()->addDocument(IndexedString(input));
92
void DUChainExtractor::parsingFinished(KDevelop::ParseJob* job)
94
KDevelop::ILanguageSupport* cppLangSup=Core::self()->languageController()->language("C++")->languageSupport();
96
DUChainReadLocker lock(DUChain::lock());
97
TopDUContext* top=cppLangSup->standardContext(input);
98
// TopDUContext* top=DUChain::self()->chainForDocument(input);
99
qDebug() << "takatakataka" << input << top << job;
102
r.setFileName(m_filename);
103
r.setIncludes(m_toinclude);
106
qDebug() << qPrintable(QString(33, '-'));
108
if(m_output.isEmpty())
109
QTextStream(stdout) << r.output;
113
if(!f.open(QIODevice::WriteOnly | QIODevice::Text))
115
QTextStream(&f) << r.output;
118
if(!m_filename.isEmpty()) {
119
QFile headerFile(m_directory+'/'+m_filename+".h");
120
if(!headerFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
121
qDebug() << "error. can't write the header: " << m_filename+".h";
125
QTextStream out(&headerFile);
126
out << r.handlersHeader;
133
r.setIncludes(m_toinclude);
136
QFile implFile(m_directory+'/'+m_filename+"impl.h");
137
if(!implFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
138
qDebug() << "error. can't write the impl: " << m_writeImpl << ".h";
142
QTextStream out(&implFile);
151
void DUChainExtractor::progressUpdated(int minimum, int maximum, int value)
153
qDebug() << "progress" << value << "/" << maximum << minimum;
156
#include "duchainextractor.moc"