1
/***************************************************************************
2
* This file is part of KDevelop *
3
* Copyright 2008 Niko Sams <niko.sams@gmail.com> *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU Library General Public License as *
7
* published by the Free Software Foundation; either version 2 of the *
8
* License, or (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU Library General Public *
16
* License along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#ifndef CONTEXTBUILDER_H
22
#define CONTEXTBUILDER_H
24
#include "phpdefaultvisitor.h"
25
#include <language/duchain/builders/abstractcontextbuilder.h>
27
#include "phpduchainexport.h"
28
#include "editorintegrator.h"
34
class EditorIntegrator;
37
typedef KDevelop::AbstractContextBuilder<AstNode, IdentifierAst> ContextBuilderBase;
39
/// first is the "pretty" identifier used for printing
40
/// second comes the all-lowercase identifier used for storage
41
typedef QPair<QString, KDevelop::QualifiedIdentifier> IdentifierPair;
43
class KDEVPHPDUCHAIN_EXPORT ContextBuilder: public ContextBuilderBase, public DefaultVisitor
48
virtual ~ContextBuilder();
50
void setEditor(EditorIntegrator* editor);
51
void setEditor(ParseSession* session);
52
virtual KDevelop::ReferencedTopDUContext build(const KDevelop::IndexedString& url, AstNode* node,
53
KDevelop::ReferencedTopDUContext updateContext
54
= KDevelop::ReferencedTopDUContext(), bool useSmart = true);
56
EditorIntegrator* editor() const;
58
virtual KDevelop::DUContext* newContext(const KDevelop::SimpleRange& range);
59
virtual KDevelop::TopDUContext* newTopContext(const KDevelop::SimpleRange& range, KDevelop::ParsingEnvironmentFile* file = 0);
61
virtual void startVisiting(AstNode* node);
62
virtual void setContextOnNode(AstNode* node, KDevelop::DUContext* ctx);
63
virtual KDevelop::DUContext* contextFromNode(AstNode* node);
64
virtual KTextEditor::Range editorFindRange(AstNode* fromRange, AstNode* toRange);
66
virtual KDevelop::QualifiedIdentifier identifierForNode(IdentifierAst* id);
67
KDevelop::QualifiedIdentifier identifierForNode(VariableIdentifierAst* id);
68
IdentifierPair identifierPairForNode(IdentifierAst* id);
69
QString stringForNode(IdentifierAst* node) const;
70
QString stringForNode(VariableIdentifierAst* node) const;
72
virtual void visitClassDeclarationStatement(ClassDeclarationStatementAst*);
73
virtual void visitInterfaceDeclarationStatement(InterfaceDeclarationStatementAst* node);
74
virtual void visitClassStatement(ClassStatementAst *node);
75
virtual void visitFunctionDeclarationStatement(FunctionDeclarationStatementAst* node);
76
virtual void visitUnaryExpression(UnaryExpressionAst* node);
78
virtual void addBaseType(IdentifierAst * identifier);
80
virtual void classContextOpened(KDevelop::DUContext* context);
82
/// Report @p errorMsg with the range of @p node
83
/// @see void reportError(const QString& errorMsg, KTextEditor::Range range);
84
void reportError(const QString& errorMsg, AstNode* node,
85
KDevelop::ProblemData::Severity severity = KDevelop::ProblemData::Error);
86
/// Report @p errorMsg with the range encompassing all nodes in @p nodes
87
/// @see void reportError(const QString& errorMsg, KTextEditor::Range range);
88
void reportError(const QString& errorMsg, QList<AstNode*> nodes,
89
KDevelop::ProblemData::Severity severity = KDevelop::ProblemData::Error);
90
/// Report @p errorMsg with range @p range
91
void reportError(const QString& errorMsg, KTextEditor::Range range,
92
KDevelop::ProblemData::Severity severity = KDevelop::ProblemData::Error);
94
KDevelop::Declaration* findDeclarationImport(DeclarationType declarationType, IdentifierAst* node);
95
KDevelop::Declaration* findDeclarationImport(DeclarationType declarationType, VariableIdentifierAst* node);
96
KDevelop::Declaration* findDeclarationImport(DeclarationType declarationType, const KDevelop::QualifiedIdentifier &identifier, AstNode* node);
98
/// InternalFunctions.php should not be checked for errors and can get some optimizations
99
bool m_isInternalFunctions;
100
/// Whether semantic problems should get reported
102
///TODO: push this into kdevplatform