Changeset View
Changeset View
Standalone View
Standalone View
duchain/builders/contextbuilder.cpp
Show All 21 Lines | |||||
22 | 22 | | |||
23 | #include <KLocalizedString> | 23 | #include <KLocalizedString> | ||
24 | 24 | | |||
25 | #include <language/duchain/duchain.h> | 25 | #include <language/duchain/duchain.h> | ||
26 | #include <language/duchain/topducontext.h> | 26 | #include <language/duchain/topducontext.h> | ||
27 | #include <language/duchain/duchainlock.h> | 27 | #include <language/duchain/duchainlock.h> | ||
28 | #include <language/duchain/declaration.h> | 28 | #include <language/duchain/declaration.h> | ||
29 | #include <language/duchain/classdeclaration.h> | 29 | #include <language/duchain/classdeclaration.h> | ||
30 | #include <language/editor/documentrange.h> | ||||
30 | 31 | | |||
31 | #include <interfaces/icore.h> | 32 | #include <interfaces/icore.h> | ||
32 | #include <interfaces/ilanguagecontroller.h> | 33 | #include <interfaces/ilanguagecontroller.h> | ||
33 | #include <interfaces/icompletionsettings.h> | 34 | #include <interfaces/icompletionsettings.h> | ||
34 | 35 | | |||
35 | #include "../editorintegrator.h" | 36 | #include "../editorintegrator.h" | ||
36 | #include "../helper.h" | 37 | #include "../helper.h" | ||
37 | #include "../duchaindebug.h" | | |||
38 | #include "../phpducontext.h" | 38 | #include "../phpducontext.h" | ||
39 | 39 | | |||
40 | #include "../parser/parsesession.h" | 40 | #include "../parser/parsesession.h" | ||
41 | #include "../parser/phpast.h" | 41 | #include "../parser/phpast.h" | ||
42 | #include <duchaindebug.h> | ||||
42 | 43 | | |||
43 | using namespace KDevelop; | 44 | using namespace KDevelop; | ||
44 | 45 | | |||
45 | namespace Php | 46 | namespace Php | ||
46 | { | 47 | { | ||
47 | 48 | | |||
48 | ContextBuilder::ContextBuilder() | 49 | ContextBuilder::ContextBuilder() | ||
49 | : m_isInternalFunctions(false), m_reportErrors(true), | 50 | : m_isInternalFunctions(false), m_reportErrors(true), | ||
50 | m_mapAst(false), m_hadUnresolvedIdentifiers(false), | 51 | m_mapAst(false), m_hadUnresolvedIdentifiers(false), | ||
51 | m_editor(0), m_openNamespaces(0) | 52 | m_editor(nullptr), m_openNamespaces(nullptr) | ||
52 | { | 53 | { | ||
53 | } | 54 | } | ||
54 | 55 | | |||
55 | ContextBuilder::~ContextBuilder() | 56 | ContextBuilder::~ContextBuilder() | ||
56 | { | 57 | { | ||
57 | } | 58 | } | ||
58 | 59 | | |||
59 | EditorIntegrator* ContextBuilder::editor() const | 60 | EditorIntegrator* ContextBuilder::editor() const | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 126 | } else { | |||
127 | top->updateImportsCache(); | 128 | top->updateImportsCache(); | ||
128 | } | 129 | } | ||
129 | } | 130 | } | ||
130 | 131 | | |||
131 | } | 132 | } | ||
132 | visitNode(node); | 133 | visitNode(node); | ||
133 | if (m_openNamespaces) { | 134 | if (m_openNamespaces) { | ||
134 | closeNamespaces(m_openNamespaces); | 135 | closeNamespaces(m_openNamespaces); | ||
135 | m_openNamespaces = 0; | 136 | m_openNamespaces = nullptr; | ||
136 | } | 137 | } | ||
137 | } | 138 | } | ||
138 | 139 | | |||
139 | DUContext* ContextBuilder::newContext(const RangeInRevision& range) | 140 | DUContext* ContextBuilder::newContext(const RangeInRevision& range) | ||
140 | { | 141 | { | ||
141 | return new PhpDUContext<DUContext>(range, currentContext()); | 142 | return new PhpDUContext<DUContext>(range, currentContext()); | ||
142 | } | 143 | } | ||
143 | 144 | | |||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | |||||
292 | void ContextBuilder::visitClosure(ClosureAst* node) | 293 | void ContextBuilder::visitClosure(ClosureAst* node) | ||
293 | { | 294 | { | ||
294 | DUContext* parameters = openContext(node->parameters, DUContext::Function); | 295 | DUContext* parameters = openContext(node->parameters, DUContext::Function); | ||
295 | Q_ASSERT(!parameters->inSymbolTable()); | 296 | Q_ASSERT(!parameters->inSymbolTable()); | ||
296 | 297 | | |||
297 | visitParameterList(node->parameters); | 298 | visitParameterList(node->parameters); | ||
298 | closeContext(); | 299 | closeContext(); | ||
299 | 300 | | |||
300 | DUContext* imported = 0; | 301 | DUContext* imported = nullptr; | ||
301 | if ( node->lexicalVars ) { | 302 | if ( node->lexicalVars ) { | ||
302 | imported = openContext(node->lexicalVars, DUContext::Other); | 303 | imported = openContext(node->lexicalVars, DUContext::Other); | ||
303 | Q_ASSERT(!imported->inSymbolTable()); | 304 | Q_ASSERT(!imported->inSymbolTable()); | ||
304 | 305 | | |||
305 | visitLexicalVarList(node->lexicalVars); | 306 | visitLexicalVarList(node->lexicalVars); | ||
306 | closeContext(); | 307 | closeContext(); | ||
307 | } | 308 | } | ||
308 | 309 | | |||
Show All 13 Lines | |||||
322 | } | 323 | } | ||
323 | } | 324 | } | ||
324 | 325 | | |||
325 | void ContextBuilder::visitNamespaceDeclarationStatement(NamespaceDeclarationStatementAst* node) | 326 | void ContextBuilder::visitNamespaceDeclarationStatement(NamespaceDeclarationStatementAst* node) | ||
326 | { | 327 | { | ||
327 | // close existing namespace context | 328 | // close existing namespace context | ||
328 | if (m_openNamespaces) { | 329 | if (m_openNamespaces) { | ||
329 | closeNamespaces(m_openNamespaces); | 330 | closeNamespaces(m_openNamespaces); | ||
330 | m_openNamespaces = 0; | 331 | m_openNamespaces = nullptr; | ||
331 | } | 332 | } | ||
332 | 333 | | |||
333 | if ( !node->namespaceNameSequence ) { | 334 | if ( !node->namespaceNameSequence ) { | ||
334 | if (node->body) { | 335 | if (node->body) { | ||
335 | // global namespace | 336 | // global namespace | ||
336 | DefaultVisitor::visitInnerStatementList(node->body); | 337 | DefaultVisitor::visitInnerStatementList(node->body); | ||
337 | } | 338 | } | ||
338 | return; | 339 | return; | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 390 | { | |||
392 | Q_ASSERT(currentContext()->type() == DUContext::Class); | 393 | Q_ASSERT(currentContext()->type() == DUContext::Class); | ||
393 | 394 | | |||
394 | ClassDeclaration* currentClass = dynamic_cast<ClassDeclaration*>(currentContext()->owner()); | 395 | ClassDeclaration* currentClass = dynamic_cast<ClassDeclaration*>(currentContext()->owner()); | ||
395 | 396 | | |||
396 | ClassDeclaration* baseClass = dynamic_cast<ClassDeclaration*>( | 397 | ClassDeclaration* baseClass = dynamic_cast<ClassDeclaration*>( | ||
397 | findDeclarationImport(ClassDeclarationType, identifierForNamespace(identifier, m_editor)).data() ); | 398 | findDeclarationImport(ClassDeclarationType, identifierForNamespace(identifier, m_editor)).data() ); | ||
398 | 399 | | |||
399 | if (currentClass && baseClass) { | 400 | if (currentClass && baseClass) { | ||
400 | if (DUContext* baseContext = baseClass->logicalInternalContext(0)) { | 401 | if (DUContext* baseContext = baseClass->logicalInternalContext(nullptr)) { | ||
401 | // prevent circular context imports which could lead to segfaults | 402 | // prevent circular context imports which could lead to segfaults | ||
402 | if (!baseContext->imports(currentContext()) && !currentContext()->imports(baseContext)) { | 403 | if (!baseContext->imports(currentContext()) && !currentContext()->imports(baseContext)) { | ||
403 | currentContext()->addImportedParentContext(baseContext); | 404 | currentContext()->addImportedParentContext(baseContext); | ||
404 | BaseClassInstance base; | 405 | BaseClassInstance base; | ||
405 | base.baseClass = baseClass->indexedType(); | 406 | base.baseClass = baseClass->indexedType(); | ||
406 | base.access = Declaration::Public; | 407 | base.access = Declaration::Public; | ||
407 | base.virtualInheritance = false; | 408 | base.virtualInheritance = false; | ||
408 | currentClass->addBaseClass(base); | 409 | currentClass->addBaseClass(base); | ||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |