-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsejob.cpp
More file actions
215 lines (180 loc) · 6.65 KB
/
parsejob.cpp
File metadata and controls
215 lines (180 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*****************************************************************************
* Copyright (c) 2007 Piyush verma <piyush.verma@gmail.com> *
* Copyright (c) 2008 Niko Sams <niko.sams@gmail.com> *
* Copyright (c) 2010 Milian Wolff <mail@milianw.de> *
* *
* 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, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "parsejob.h"
#include <QFile>
#include <QReadWriteLock>
#include <QtCore/QReadLocker>
#include <QtCore/QThread>
#include <kdebug.h>
#include <KMimeType>
#include <language/duchain/duchainlock.h>
#include <language/duchain/duchain.h>
#include <language/duchain/topducontext.h>
#include <language/duchain/dumpchain.h>
#include <language/backgroundparser/urlparselock.h>
#include <interfaces/ilanguage.h>
#include <language/highlighting/codehighlighting.h>
#include <interfaces/icore.h>
#include <interfaces/ilanguagecontroller.h>
#include "parser/parsesession.h"
#include "erlanglanguagesupport.h"
#include "duchain/builders/declarationbuilder.h"
#include "parser/editorintegrator.h"
#include <QtCore/QReadLocker>
#include <QtCore/QThread>
using namespace KDevelop;
namespace erlang
{
extern int debugArea();
#define debug() kDebug(debugArea())
ParseJob::ParseJob ( const KUrl &url )
: KDevelop::ParseJob ( url )
{
kDebug();
}
ParseJob::~ParseJob()
{
kDebug();
}
LanguageSupport *ParseJob::erlang() const
{
return LanguageSupport::self();
}
void ParseJob::run()
{
KDevelop::UrlParseLock urlLock ( document() );
if ( ! ( minimumFeatures() & KDevelop::TopDUContext::ForceUpdate ) )
{
KDevelop::DUChainReadLocker lock ( KDevelop::DUChain::lock() );
bool needsUpdate = true;
foreach ( const KDevelop::ParsingEnvironmentFilePointer &file, KDevelop::DUChain::self()->allEnvironmentFiles ( document() ) )
{
if ( file->needsUpdate() )
{
needsUpdate = true;
break;
}
else
{
needsUpdate = false;
}
}
if ( !needsUpdate )
{
debug() << "Already up to date" << document().str();
return;
}
}
debug() << "parsing" << document().str();
bool readFromDisk = !contentsAvailableFromEditor();
QString contents;
if ( readFromDisk )
{
QFile file ( document().str() );
if ( !file.open ( QIODevice::ReadOnly | QIODevice::Text ) )
{
/*
KDevelop::ProblemPointer p(new KDevelop::Problem());
p->setSource(KDevelop::ProblemData::Disk);
p->setDescription(i18n("Could not open file '%1'", document().str()));
switch (file.error()) {
case QFile::ReadError:
p->setExplanation(i18n("File could not be read from."));
break;
case QFile::OpenError:
p->setExplanation(i18n("File could not be opened."));
break;
case QFile::PermissionsError:
p->setExplanation(i18n("File permissions prevent opening for read."));
break;
default:
break;
}
p->setFinalLocation(KDevelop::DocumentRange(document().str(), KTextEditor::Cursor(0, 0), KTextEditor::Cursor(0, 0)));
// TODO addProblem(p);
*/
kWarning() << "Could not open file" << document().str();
return abortJob();
}
QTextStream s ( &file );
contents = s.readAll();
file.close();
}
else
{
contents = contentsFromEditor();
}
KDevelop::ReferencedTopDUContext top;
{
KDevelop::DUChainReadLocker lock ( KDevelop::DUChain::lock() );
top = KDevelop::DUChain::self()->chainForDocument ( document() );
}
if ( top )
{
debug() << "re-compiling" << document().str();
KDevelop::DUChainWriteLocker lock ( KDevelop::DUChain::lock() );
top->clearImportedParentContexts();
top->parsingEnvironmentFile()->clearModificationRevisions();
top->clearProblems();
}
else
{
debug() << "compiling" << document().str();
}
QReadLocker parseLock ( erlang()->language()->parseLock() );
FormAst* formAst = 0;
ParseSession parseSession;
parseSession.setContents ( contents );
parseSession.setCurrentDocument ( document().str() );
bool matched = parseSession.parse ( &formAst );
EditorIntegrator editor;
editor.setParseSession(&parseSession);
DeclarationBuilder builder;
builder.setEditor ( &editor );
top = builder.build ( document(), formAst, top );
kDebug() << top;
Q_ASSERT ( top );
setDuChain ( top );
KDevelop::DUChainWriteLocker lock ( KDevelop::DUChain::lock() );
if ( !matched )
{
foreach ( const ProblemPointer &p, parseSession.problems() )
{
top->addProblem ( p );
}
}
cleanupSmartRevision();
top->setFeatures ( minimumFeatures() );
KDevelop::ParsingEnvironmentFilePointer file = top->parsingEnvironmentFile();
QFileInfo fileInfo ( document().str() );
QDateTime lastModified = fileInfo.lastModified();
if ( readFromDisk )
{
file->setModificationRevision ( KDevelop::ModificationRevision ( lastModified ) );
}
else
{
file->setModificationRevision ( KDevelop::ModificationRevision ( lastModified, revisionToken() ) );
}
KDevelop::DUChain::self()->updateContextEnvironment ( top->topContext(), file.data() );
cleanupSmartRevision();
}
}
#include "parsejob.moc"
// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on; auto-insert-doxygen on