1
/***************************************************************************
2
* This file is part of KDevelop *
3
* Copyright 2007 David Nolden <david.nolden.kdevelop@art-master.de> *
4
* Copyright 2008 Niko Sams <niko.sams@gmail.com> *
6
* This program is free software; you can redistribute it and/or modify *
7
* it under the terms of the GNU Library General Public License as *
8
* published by the Free Software Foundation; either version 2 of the *
9
* License, or (at your option) any later version. *
11
* This program is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this program; if not, write to the *
18
* Free Software Foundation, Inc., *
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20
***************************************************************************/
21
#include "expressionparser.h"
22
#include "parsesession.h"
23
#include "editorintegrator.h"
25
#include "phpparser.h"
26
#include "phpdebugvisitor.h"
27
#include "expressionvisitor.h"
29
#include <language/duchain/ducontext.h>
30
#include <language/duchain/duchainlock.h>
31
#include <language/duchain/duchain.h>
34
using namespace KDevelop;
39
ExpressionParser::ExpressionParser(bool debug)
40
: m_debug(debug), m_createProblems(false)
44
void ExpressionParser::setCreateProblems(bool v)
49
ExpressionEvaluationResult ExpressionParser::evaluateType(const QByteArray& expression, DUContextPointer context,
50
const SimpleCursor &offset)
53
kDebug() << "==== .Evaluating ..:" << endl << expression;
55
ParseSession* session = new ParseSession();
56
session->setContents(expression);
57
Parser* parser = session->createParser(Parser::DefaultState);
59
if (!parser->parseExpr(&ast)) {
60
kDebug() << "Failed to parse \"" << expression << "\"";
63
return ExpressionEvaluationResult();
65
ast->ducontext = dynamic_cast<DUContext*>(context.data());
67
EditorIntegrator* editor = new EditorIntegrator(session);
68
ExpressionEvaluationResult ret = evaluateType(ast, editor, offset);
76
ExpressionEvaluationResult ExpressionParser::evaluateType(AstNode* ast, EditorIntegrator* editor)
78
return evaluateType(ast, editor, SimpleCursor::invalid());
81
ExpressionEvaluationResult ExpressionParser::evaluateType(AstNode* ast, EditorIntegrator* editor,
82
const SimpleCursor &offset)
85
kDebug() << "===== AST:";
86
DebugVisitor debugVisitor(editor->parseSession()->tokenStream(), editor->parseSession()->contents());
87
debugVisitor.visitNode(ast);
90
ExpressionVisitor v(editor);
92
v.setCreateProblems(m_createProblems);