25
25
#include <language/duchain/duchainlock.h>
26
26
#include <language/duchain/topducontext.h>
27
27
#include <language/duchain/indexedstring.h>
28
#include <language/duchain/dumpchain.h>
28
29
#include <kstandarddirs.h>
29
30
#include <kcomponentdata.h>
105
105
TopDUContext* DUChainTestBase::parseAdditionalFile(const IndexedString& fileName, const QByteArray& contents)
107
ParseSession* session = new ParseSession();
108
session->setContents(contents);
107
ParseSession session;
108
session.setContents(contents);
109
109
StartAst* ast = 0;
110
if (!session->parse(&ast)) qFatal("can't parse");
110
if (!session.parse(&ast)) qFatal("can't parse");
112
DeclarationBuilder declarationBuilder(session);
112
EditorIntegrator editor(&session);
113
session.setCurrentDocument(fileName);
114
DeclarationBuilder declarationBuilder(&editor);
113
115
TopDUContext* top = declarationBuilder.build(fileName, ast);
115
117
if ( fileName != internalFunctionFile() ) {
116
UseBuilder useBuilder(session);
118
UseBuilder useBuilder(&editor);
117
119
useBuilder.buildUses(ast);
120
if (!session->problems().isEmpty()) {
122
if (!session.problems().isEmpty()) {
121
123
DUChainWriteLocker lock;
122
foreach( const ProblemPointer& p, session->problems() ) {
124
foreach( const ProblemPointer& p, session.problems() ) {
123
125
top->addProblem(p);
135
135
kDebug() << "==== Beginning new test case...:" << endl << unit;
137
ParseSession* session = new ParseSession();
138
session->setContents(unit);
137
ParseSession session;
138
session.setContents(unit);
139
139
StartAst* ast = 0;
140
if (!session->parse(&ast)) {
140
if (!session.parse(&ast)) {
141
141
kDebug() << "Parse failed";
145
145
if (dump & DumpAST) {
146
146
kDebug() << "===== AST:";
147
DebugVisitor debugVisitor(session->tokenStream(), session->contents());
147
DebugVisitor debugVisitor(session.tokenStream(), session.contents());
148
148
debugVisitor.visitNode(ast);
151
151
static int testNumber = 0;
152
152
if (url.isEmpty()) url = QString("file:///internal/%1").arg(testNumber++);
155
DeclarationBuilder declarationBuilder(session);
156
TopDUContext* top = declarationBuilder.build(IndexedString(url), ast);
158
if (!session->problems().isEmpty()) {
154
EditorIntegrator editor(&session);
155
session.setCurrentDocument(IndexedString(url));
156
DeclarationBuilder declarationBuilder(&editor);
157
TopDUContext* top = declarationBuilder.build(session.currentDocument(), ast);
159
if (!session.problems().isEmpty()) {
159
160
DUChainWriteLocker lock;
160
foreach( const ProblemPointer& p, session->problems() ) {
161
foreach( const ProblemPointer& p, session.problems() ) {
161
162
top->addProblem(p);
165
166
if ( IndexedString(url) != internalFunctionFile() ) {
166
UseBuilder useBuilder(session);
167
UseBuilder useBuilder(&editor);
167
168
useBuilder.buildUses(ast);
171
172
kDebug() << "===== DUChain:";
173
174
DUChainWriteLocker lock(DUChain::lock());
177
178
if (dump & DumpType) {
178
179
kDebug() << "===== Types:";
179
180
DUChainWriteLocker lock(DUChain::lock());
181
foreach(const AbstractType::Ptr& type, declarationBuilder.topTypes())
182
dt.dump(type.unsafeData());
182
foreach(const AbstractType::Ptr& type, declarationBuilder.topTypes()) {
183
dt.dump(type.unsafeData());
186
188
kDebug() << "===== Finished test case.";