-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsejob.cpp
More file actions
175 lines (138 loc) · 4.8 KB
/
parsejob.cpp
File metadata and controls
175 lines (138 loc) · 4.8 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
/*
* This file is part of KDevelop
*
* Copyright 2008-2010 Alexander Dymo <adymo@kdevelop.org>
*
* 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.
*/
#include "parsejob.h"
#include <cassert>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "Thread.h"
#include <QFile>
#include <QRegExp>
#include <QByteArray>
#include <QReadLocker>
#include <kdebug.h>
#include <klocale.h>
#include <ktexteditor/document.h>
#include <interfaces/ilanguage.h>
#include <language/duchain/duchain.h>
#include <language/duchain/problem.h>
#include <language/duchain/duchainlock.h>
#include <language/duchain/declaration.h>
#include <language/duchain/topducontext.h>
#include <language/duchain/parsingenvironment.h>
#include <language/duchain/persistentsymboltable.h>
#include <language/backgroundparser/urlparselock.h>
#include "rubylanguagesupport.h"
#include "parser/parser.h"
#include "duchain/declarationbuilder.h"
#include "duchain/editorintegrator.h"
using namespace KDevelop;
namespace Ruby
{
SimpleParseJob::SimpleParseJob( const KDevelop::IndexedString &url, RubyLanguageSupport *parent )
: KDevelop::ParseJob( url, parent ), m_parser(new Parser), m_readFromDisk( false )
{}
SimpleParseJob::~SimpleParseJob()
{}
RubyLanguageSupport *SimpleParseJob::ruby() const
{
return RubyLanguageSupport::self();
}
bool SimpleParseJob::wasReadFromDisk() const
{
return m_readFromDisk;
}
void SimpleParseJob::run()
{
kDebug() << "Trying to run ruby parse job";
//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();
QString c = contents().contents;
kDebug() << "===-- PARSING --===> "
<< document().str()
<< " <== readFromDisk: " << m_readFromDisk
<< " size: " << c.size()
<< endl;
if ( abortRequested() )
return abortJob();
parse(c);
if ( abortRequested() )
return abortJob();
}
void SimpleParseJob::parse(const QString &c)
{
ProgramAST *programAST = m_parser->parse(c);
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"