~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to duchain/tests/duchaintestbase.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-12-20 14:59:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101220145902-a6cmovse1qmue52p
Tags: 1.1.80-0ubuntu1
* New upstream release
* Build-dep on kdevplatform >= 1.1.80
* Get rid of l10n packages, not relevant in Ubuntu, put locale files into main package

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
30
31
 
40
41
#include <tests/testcore.h>
41
42
#include <language/codegen/coderepresentation.h>
42
43
 
43
 
using namespace KTextEditor;
44
44
using namespace KDevelop;
45
45
 
46
46
 
104
104
 
105
105
TopDUContext* DUChainTestBase::parseAdditionalFile(const IndexedString& fileName, const QByteArray& contents)
106
106
{
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");
111
111
 
112
 
    DeclarationBuilder declarationBuilder(session);
 
112
    EditorIntegrator editor(&session);
 
113
    session.setCurrentDocument(fileName);
 
114
    DeclarationBuilder declarationBuilder(&editor);
113
115
    TopDUContext* top = declarationBuilder.build(fileName, ast);
114
116
 
115
117
    if ( fileName != internalFunctionFile() ) {
116
 
        UseBuilder useBuilder(session);
 
118
        UseBuilder useBuilder(&editor);
117
119
        useBuilder.buildUses(ast);
118
120
    }
119
121
 
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);
124
126
        }
125
127
    }
126
128
 
127
 
    delete session;
128
 
 
129
129
    return top;
130
130
}
131
131
 
134
134
    if (dump)
135
135
        kDebug() << "==== Beginning new test case...:" << endl << unit;
136
136
 
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";
142
142
        return 0;
143
143
    }
144
144
 
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);
149
149
    }
150
150
 
151
151
    static int testNumber = 0;
152
152
    if (url.isEmpty()) url = QString("file:///internal/%1").arg(testNumber++);
153
153
 
154
 
 
155
 
    DeclarationBuilder declarationBuilder(session);
156
 
    TopDUContext* top = declarationBuilder.build(IndexedString(url), ast);
157
 
 
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);
 
158
 
 
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);
162
163
        }
163
164
    }
164
165
 
165
166
    if ( IndexedString(url) != internalFunctionFile() ) {
166
 
        UseBuilder useBuilder(session);
 
167
        UseBuilder useBuilder(&editor);
167
168
        useBuilder.buildUses(ast);
168
169
    }
169
170
 
171
172
        kDebug() << "===== DUChain:";
172
173
 
173
174
        DUChainWriteLocker lock(DUChain::lock());
174
 
        dumper.dump(top);
 
175
        dumpDUContext(top);
175
176
    }
176
177
 
177
178
    if (dump & DumpType) {
178
179
        kDebug() << "===== Types:";
179
180
        DUChainWriteLocker lock(DUChain::lock());
180
181
        DumpTypes dt;
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());
 
184
        }
183
185
    }
184
186
 
185
187
    if (dump)
186
188
        kDebug() << "===== Finished test case.";
187
189
 
188
 
    delete session;
189
 
 
190
190
    return top;
191
191
}
192
192
}