Commit 11ccb571 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Improved the DuiDocument and keep a working copy of the document in the...

Improved the DuiDocument and keep a working copy of the document in the editor, also use the QML api.
parent 473b6abb
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#include "duidocument.h"
#include "parser/javascriptast_p.h"
#include "parser/javascriptlexer_p.h"
......@@ -31,7 +60,7 @@ AST::UiProgram *DuiDocument::program() const
return _program;
}
QList<JavaScriptParser::DiagnosticMessage> DuiDocument::diagnosticMessages() const
QList<DiagnosticMessage> DuiDocument::diagnosticMessages() const
{
return _diagnosticMessages;
}
......@@ -47,20 +76,15 @@ bool DuiDocument::parse()
Q_ASSERT(! _pool);
Q_ASSERT(! _program);
_engine = new JavaScriptEnginePrivate();
_engine = new Engine();
_pool = new NodePool(_fileName, _engine);
JavaScriptParser parser;
NodePool nodePool(_fileName, _engine);
_engine->setNodePool(_pool);
Lexer lexer(_engine);
_engine->setLexer(&lexer);
Parser parser(_engine);
lexer.setCode(_source, /*line = */ 1);
bool parsed = parser.parse(_engine);
bool parsed = parser.parse();
_program = parser.ast();
_diagnosticMessages = parser.diagnosticMessages();
return parsed;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#ifndef DUIDOCUMENT_H
#define DUIDOCUMENT_H
......@@ -5,22 +33,8 @@
#include <QtCore/QMap>
#include <QtCore/QString>
#include "parser/javascriptparser_p.h"
class JavaScriptEnginePrivate;
namespace JavaScript {
class NodePool;
namespace AST {
class UiProgram;
} // end of namespace AST
} // end of namespace JavaScript
#include "parser/javascriptengine_p.h"
#include "parser/javascriptastfwd_p.h"
namespace DuiEditor {
namespace Internal {
......@@ -39,16 +53,16 @@ public:
static DuiDocument::Ptr create(const QString &fileName);
JavaScript::AST::UiProgram *program() const;
QList<JavaScriptParser::DiagnosticMessage> diagnosticMessages() const;
QList<JavaScript::DiagnosticMessage> diagnosticMessages() const;
void setSource(const QString &source);
bool parse();
private:
JavaScriptEnginePrivate *_engine;
JavaScript::Engine *_engine;
JavaScript::NodePool *_pool;
JavaScript::AST::UiProgram *_program;
QList<JavaScriptParser::DiagnosticMessage> _diagnosticMessages;
QList<JavaScript::DiagnosticMessage> _diagnosticMessages;
QString _fileName;
QString _source;
};
......
......@@ -438,6 +438,7 @@ void ScriptEditor::updateDocumentNow()
DuiDocument::Ptr doc = DuiDocument::create(fileName);
doc->setSource(source);
bool parsed = doc->parse();
m_document = doc;
FindIdDeclarations updateIds;
m_ids = updateIds(doc->program());
......@@ -470,7 +471,7 @@ void ScriptEditor::updateDocumentNow()
m_diagnosticMessages = doc->diagnosticMessages();
foreach (const JavaScriptParser::DiagnosticMessage &d, m_diagnosticMessages) {
foreach (const DiagnosticMessage &d, m_diagnosticMessages) {
int line = d.loc.startLine;
int column = d.loc.startColumn;
......
......@@ -31,8 +31,11 @@
#define DUIDITORW_H
#include <texteditor/basetexteditor.h>
#include <parser/javascriptast_p.h>
#include <parser/javascriptparser_p.h>
#include "parser/javascriptastfwd_p.h"
#include "parser/javascriptengine_p.h"
#include "duidocument.h"
QT_BEGIN_NAMESPACE
class QComboBox;
......@@ -98,7 +101,7 @@ public:
QStringList words() const;
QStringList keywords() const;
QList<JavaScriptParser::DiagnosticMessage> diagnosticMessages() const
QList<JavaScript::DiagnosticMessage> diagnosticMessages() const
{ return m_diagnosticMessages; }
public slots:
......@@ -133,7 +136,8 @@ private:
QList<Declaration> m_declarations;
QStringList m_words;
QMap<QString, QList<JavaScript::AST::SourceLocation> > m_ids; // ### use QMultiMap
QList<JavaScriptParser::DiagnosticMessage> m_diagnosticMessages;
QList<JavaScript::DiagnosticMessage> m_diagnosticMessages;
DuiDocument::Ptr m_document;
};
} // namespace Internal
......
......@@ -92,7 +92,7 @@ void DuiHoverHandler::showToolTip(TextEditor::ITextEditor *editor, const QPoint
tc.setPosition(pos);
const unsigned line = tc.block().blockNumber() + 1;
foreach (const JavaScriptParser::DiagnosticMessage &m, ed->diagnosticMessages()) {
foreach (const JavaScript::DiagnosticMessage &m, ed->diagnosticMessages()) {
if (m.loc.startLine == line) {
m_toolTip.append(m.message);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment