From c45c48bdfa21cf474cbcd704e67ae81df7704188 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Thu, 8 Jan 2009 13:06:09 +0100 Subject: [PATCH 01/12] Return true if we can recognize an objc-identifier-list. --- shared/cplusplus/Parser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/shared/cplusplus/Parser.cpp b/shared/cplusplus/Parser.cpp index 2b312b08add..c1e48f233f4 100644 --- a/shared/cplusplus/Parser.cpp +++ b/shared/cplusplus/Parser.cpp @@ -3376,6 +3376,7 @@ bool Parser::parseObjCIdentifierList(IdentifierListAST *&node) *it = id; } } + return true; } return false; } From ef259344c5d71947d597b7a1fccf98b75cea075a Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 8 Jan 2009 13:16:04 +0100 Subject: [PATCH 02/12] make the key handlers return a bool indication whether they acted on the key or not. --- src/plugins/fakevim/handler.cpp | 55 +++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/plugins/fakevim/handler.cpp b/src/plugins/fakevim/handler.cpp index 08063dc5a35..689f4d6dd8a 100644 --- a/src/plugins/fakevim/handler.cpp +++ b/src/plugins/fakevim/handler.cpp @@ -98,7 +98,7 @@ enum SubSubMode NoSubSubMode, FtSubSubMode, // used for f, F, t, T MarkSubSubMode, // used for m - BackTickSubSubMode, // used for ` + BackTickSubSubMode, // used for ` TickSubSubMode // used for ' }; @@ -146,11 +146,11 @@ private: static int control(int key) { return key + 256; } void init(); - void handleKey(int key, const QString &text); - void handleInsertMode(int key, const QString &text); - void handleCommandMode(int key, const QString &text); - void handleRegisterMode(int key, const QString &text); - void handleMiniBufferModes(int key, const QString &text); + bool handleKey(int key, const QString &text); + bool handleInsertMode(int key, const QString &text); + bool handleCommandMode(int key, const QString &text); + bool handleRegisterMode(int key, const QString &text); + bool handleMiniBufferModes(int key, const QString &text); void finishMovement(const QString &text = QString()); void search(const QString &needle, bool forward); @@ -214,7 +214,7 @@ private: bool isSearchMode() const { return m_mode == SearchForwardMode || m_mode == SearchBackwardMode; } int m_gflag; // whether current command started with 'g' - + QString m_commandBuffer; QString m_currentFileName; QString m_currentMessage; @@ -312,17 +312,18 @@ bool FakeVimHandler::Private::eventFilter(QObject *ob, QEvent *ev) return true; } -void FakeVimHandler::Private::handleKey(int key, const QString &text) +bool FakeVimHandler::Private::handleKey(int key, const QString &text) { //qDebug() << "KEY: " << key << text << "POS: " << m_tc.position(); //qDebug() << "\nUNDO: " << m_undoStack << "\nREDO: " << m_redoStack; if (m_mode == InsertMode) - handleInsertMode(key, text); - else if (m_mode == CommandMode) - handleCommandMode(key, text); - else if (m_mode == ExMode || m_mode == SearchForwardMode + return handleInsertMode(key, text); + if (m_mode == CommandMode) + return handleCommandMode(key, text); + if (m_mode == ExMode || m_mode == SearchForwardMode || m_mode == SearchBackwardMode) - handleMiniBufferModes(key, text); + return handleMiniBufferModes(key, text); + return false; } void FakeVimHandler::Private::finishMovement(const QString &dotCommand) @@ -417,11 +418,11 @@ void FakeVimHandler::Private::updateMiniBuffer() } else if (m_mode == InsertMode) { msg = "-- INSERT --"; } else { - if (m_mode == SearchForwardMode) + if (m_mode == SearchForwardMode) msg += '/'; - else if (m_mode == SearchBackwardMode) + else if (m_mode == SearchBackwardMode) msg += '?'; - else if (m_mode == ExMode) + else if (m_mode == ExMode) msg += ':'; foreach (QChar c, m_commandBuffer) { if (c.unicode() < 32) { @@ -456,7 +457,7 @@ void FakeVimHandler::Private::showMessage(const QString &msg) updateMiniBuffer(); } -void FakeVimHandler::Private::handleCommandMode(int key, const QString &text) +bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) { Q_UNUSED(text) @@ -742,10 +743,12 @@ void FakeVimHandler::Private::handleCommandMode(int key, const QString &text) leaveVisualMode(); } else { qDebug() << "Ignored" << key << text; - } + return false; + } + return true; } -void FakeVimHandler::Private::handleInsertMode(int key, const QString &text) +bool FakeVimHandler::Private::handleInsertMode(int key, const QString &text) { if (key == Key_Escape) { // start with '1', as one instance was already physically inserted @@ -789,14 +792,17 @@ void FakeVimHandler::Private::handleInsertMode(int key, const QString &text) m_lastInsertion.clear(); } else if (key == Key_Backspace) { finishMovement(); - } else { + } else if (!text.isEmpty()) { m_lastInsertion.append(text); m_tc.insertText(text); + } else { + return false; } updateMiniBuffer(); + return true; } -void FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text) +bool FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text) { Q_UNUSED(text) @@ -848,7 +854,7 @@ void FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text } else if (key == Key_Down && m_mode == ExMode) { if (m_commandHistoryIndex < m_commandHistory.size() - 1) { ++m_commandHistoryIndex; - m_commandBuffer = m_commandHistory.at(m_commandHistoryIndex); + m_commandBuffer = m_commandHistory.at(m_commandHistoryIndex); updateMiniBuffer(); } } else if (key == Key_Tab) { @@ -858,6 +864,7 @@ void FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text m_commandBuffer += QChar(key); updateMiniBuffer(); } + return true; } // 1 based. @@ -904,7 +911,7 @@ int FakeVimHandler::Private::readLineCode(QString &cmd) } // not parsed cmd = c + cmd; - return -1; + return -1; } QTextCursor FakeVimHandler::Private::selectRange(int beginLine, int endLine) @@ -932,7 +939,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) int line = readLineCode(cmd); if (line != -1) beginLine = line; - + if (cmd.startsWith(',')) { cmd = cmd.mid(1); line = readLineCode(cmd); From 95fbb4842b7a03b2830f1385d438d4b4f812b540 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 8 Jan 2009 13:43:24 +0100 Subject: [PATCH 03/12] handle 'P' --- src/plugins/fakevim/handler.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/plugins/fakevim/handler.cpp b/src/plugins/fakevim/handler.cpp index 689f4d6dd8a..3d3c228a12a 100644 --- a/src/plugins/fakevim/handler.cpp +++ b/src/plugins/fakevim/handler.cpp @@ -299,7 +299,7 @@ bool FakeVimHandler::Private::eventFilter(QObject *ob, QEvent *ev) key += 32; if ((keyEvent->modifiers() & Qt::ControlModifier) != 0) key += 256; - handleKey(key, keyEvent->text()); + bool handled = handleKey(key, keyEvent->text()); // We fake vi-style end-of-line behaviour m_fakeEnd = (atEol() && m_mode == CommandMode); @@ -309,7 +309,7 @@ bool FakeVimHandler::Private::eventFilter(QObject *ob, QEvent *ev) EDITOR(setTextCursor(m_tc)); EDITOR(ensureCursorVisible()); - return true; + return handled; } bool FakeVimHandler::Private::handleKey(int key, const QString &text) @@ -669,16 +669,18 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) m_tc.movePosition(StartOfLine, MoveAnchor); m_tc.movePosition(Left, MoveAnchor, 1); m_tc.insertText("\n"); - } else if (key == 'p') { + } else if (key == 'p' || key == 'P') { QString text = m_registers[m_register]; int n = text.count(QChar(ParagraphSeparator)); if (n > 0) { m_tc.movePosition(StartOfLine); - m_tc.movePosition(Down); + if (key == 'p') + m_tc.movePosition(Down); m_tc.insertText(text); m_tc.movePosition(Up, MoveAnchor, n); } else { - m_tc.movePosition(Right); + if (key == 'p') + m_tc.movePosition(Right); m_tc.insertText(text); m_tc.movePosition(Left); } From 0225cc85ca3c6616925e2f02b33c4fb85be39011 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Thu, 8 Jan 2009 13:24:02 -0800 Subject: [PATCH 04/12] centralize runstep definitions further --- src/plugins/qt4projectmanager/deployhelper.cpp | 3 ++- src/plugins/qt4projectmanager/qt4projectmanagerconstants.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/qt4projectmanager/deployhelper.cpp b/src/plugins/qt4projectmanager/deployhelper.cpp index 807725751a0..865d26e15a5 100644 --- a/src/plugins/qt4projectmanager/deployhelper.cpp +++ b/src/plugins/qt4projectmanager/deployhelper.cpp @@ -33,6 +33,7 @@ #include "deployhelper.h" #include "qt4project.h" +#include "qt4projectmanagerconstants.h" #include #include @@ -183,7 +184,7 @@ void DeployHelperRunStep::readyRead() QString DeployHelperRunStep::name() { - return "trolltech.qt4projectmanager.deployhelperrunstep"; + return Constants::DEPLOYHELPERRUNSTEP; } QString DeployHelperRunStep::displayName() diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerconstants.h b/src/plugins/qt4projectmanager/qt4projectmanagerconstants.h index 251f47dcf13..e76b4ef5f8c 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanagerconstants.h +++ b/src/plugins/qt4projectmanager/qt4projectmanagerconstants.h @@ -77,6 +77,7 @@ const char * const QMAKESTEP = "trolltech.qt4projectmanager.qmake"; const char * const MAKESTEP = "trolltech.qt4projectmanager.make"; const char * const GDBMACROSBUILDSTEP = "trolltech.qt4projectmanager.gdbmaros"; const char * const QT4RUNSTEP = "trolltech.qt4projectmanager.qt4runstep"; +const char * const DEPLOYHELPERRUNSTEP = "trolltech.qt4projectmanager.deployhelperrunstep"; // build parsers const char * const BUILD_PARSER_MSVC = "BuildParser.MSVC"; From 2c74d01e94e66f4c04ee27b9c6384dc51e4c97ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 8 Jan 2009 13:44:37 +0100 Subject: [PATCH 05/12] Fixed 'make docs' lauching of qhelpgenerator It assumed qhelpgenerator was in the path, though this isn't necessarily the case. Use the absolute directory instead. --- doc/doc.pri | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/doc.pri b/doc/doc.pri index cb800823ec4..d8e65d4a944 100644 --- a/doc/doc.pri +++ b/doc/doc.pri @@ -1,9 +1,9 @@ unix { QDOC = SRCDIR=$$PWD OUTDIR=$$OUT_PWD/doc/html $$(QTDIR)/tools/qdoc3/qdoc3 - HELPGENERATOR = qhelpgenerator + HELPGENERATOR = $$(QTDIR)/bin/qhelpgenerator } else { QDOC = $$(QTDIR)\tools\qdoc3\release\qdoc3.exe - HELPGENERATOR = qhelpgenerator + HELPGENERATOR = $$(QTDIR)\bin\qhelpgenerator.exe } QHP_FILE = $$OUT_PWD/doc/html/qtcreator.qhp From 171a3bb8d2977380a1d8b668fecab11bba608ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 8 Jan 2009 15:09:21 +0100 Subject: [PATCH 06/12] Fixed compilation problem with gcc 3.3 Reviewed-by: Roberto Raggi --- src/plugins/cpptools/cppcodecompletion.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp index b1184420bf6..2cd859ecb9e 100644 --- a/src/plugins/cpptools/cppcodecompletion.cpp +++ b/src/plugins/cpptools/cppcodecompletion.cpp @@ -723,7 +723,7 @@ bool CppCodeCompletion::completeScope(const QList &res return false; // nothing to do. // Search for a class or a namespace. - TypeOfExpression::Result result(FullySpecifiedType(), 0); + TypeOfExpression::Result result; foreach (result, results) { FullySpecifiedType ty = result.first; @@ -751,8 +751,7 @@ bool CppCodeCompletion::completeScope(const QList &res } else if (Symbol *symbol = result.second) { if (symbol->isTypedef()) { ResolveClass resolveClass; - const QList candidates = resolveClass(result, - context); + const QList candidates = resolveClass(result, context); completeClass(candidates, context); } } From 57ab0b9e8e2006f85bd6841bd7a4fac5932397cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 8 Jan 2009 16:15:25 +0100 Subject: [PATCH 07/12] Changed categories used for pro file highlighting Now reuses the colors set for Type and Keyword for the variables and functions respectively. Having the categories Variable and Function in the fonts and color settings was confusing. --- .../qt4projectmanager/profileeditor.cpp | 4 +- .../profileeditorfactory.cpp | 1 - .../qt4projectmanager/profilehighlighter.h | 8 ++- .../qt4projectmanager/qt4projectmanager.pro | 3 -- .../qt4projectmanagerenums.h | 50 ------------------- src/plugins/texteditor/texteditorconstants.h | 3 -- src/plugins/texteditor/texteditorsettings.cpp | 4 -- 7 files changed, 9 insertions(+), 64 deletions(-) delete mode 100644 src/plugins/qt4projectmanager/qt4projectmanagerenums.h diff --git a/src/plugins/qt4projectmanager/profileeditor.cpp b/src/plugins/qt4projectmanager/profileeditor.cpp index ddcb0b4252b..6d4f36f1f79 100644 --- a/src/plugins/qt4projectmanager/profileeditor.cpp +++ b/src/plugins/qt4projectmanager/profileeditor.cpp @@ -132,8 +132,8 @@ void ProFileEditor::setFontSettings(const TextEditor::FontSettings &fs) static QVector categories; if (categories.isEmpty()) { - categories << QLatin1String(TextEditor::Constants::C_VARIABLE) - << QLatin1String(TextEditor::Constants::C_FUNCTION) + categories << QLatin1String(TextEditor::Constants::C_TYPE) + << QLatin1String(TextEditor::Constants::C_KEYWORD) << QLatin1String(TextEditor::Constants::C_COMMENT); } diff --git a/src/plugins/qt4projectmanager/profileeditorfactory.cpp b/src/plugins/qt4projectmanager/profileeditorfactory.cpp index a18fda7b5d9..bc9e1729eb4 100644 --- a/src/plugins/qt4projectmanager/profileeditorfactory.cpp +++ b/src/plugins/qt4projectmanager/profileeditorfactory.cpp @@ -36,7 +36,6 @@ #include "qt4projectmanager.h" #include "qt4projectmanagerconstants.h" #include "profileeditor.h" -#include "qt4projectmanagerenums.h" #include #include diff --git a/src/plugins/qt4projectmanager/profilehighlighter.h b/src/plugins/qt4projectmanager/profilehighlighter.h index 7dd2ccd5a9c..5d603cae160 100644 --- a/src/plugins/qt4projectmanager/profilehighlighter.h +++ b/src/plugins/qt4projectmanager/profilehighlighter.h @@ -47,6 +47,13 @@ class ProFileHighlighter : public QSyntaxHighlighter { Q_OBJECT public: + enum ProfileFormats { + ProfileVariableFormat, + ProfileFunctionFormat, + ProfileCommentFormat, + NumProfileFormats + }; + ProFileHighlighter(QTextDocument *document = 0); virtual void highlightBlock(const QString &text); @@ -58,7 +65,6 @@ public: private: QTextCharFormat m_formats[NumProfileFormats]; - }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.pro b/src/plugins/qt4projectmanager/qt4projectmanager.pro index fa291eadd24..c7dc608437f 100644 --- a/src/plugins/qt4projectmanager/qt4projectmanager.pro +++ b/src/plugins/qt4projectmanager/qt4projectmanager.pro @@ -5,7 +5,6 @@ include(../../qworkbenchplugin.pri) include(qt4projectmanager_dependencies.pri) HEADERS = qt4projectmanagerplugin.h \ qt4projectmanager.h \ - qt4projectmanagerenums.h \ qtversionmanager.h \ qt4project.h \ qt4nodes.h \ @@ -45,7 +44,6 @@ HEADERS = qt4projectmanagerplugin.h \ projectloadwizard.h \ directorywatcher.h \ gdbmacrosbuildstep.h - SOURCES = qt4projectmanagerplugin.cpp \ qt4projectmanager.cpp \ qtversionmanager.cpp \ @@ -84,7 +82,6 @@ SOURCES = qt4projectmanagerplugin.cpp \ projectloadwizard.cpp \ directorywatcher.cpp \ gdbmacrosbuildstep.cpp - FORMS = qtversionmanager.ui \ envvariablespage.ui \ enveditdialog.ui \ diff --git a/src/plugins/qt4projectmanager/qt4projectmanagerenums.h b/src/plugins/qt4projectmanager/qt4projectmanagerenums.h deleted file mode 100644 index 247dae0117f..00000000000 --- a/src/plugins/qt4projectmanager/qt4projectmanagerenums.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Qt Software Information (qt-info@nokia.com) -** -** -** Non-Open Source Usage -** -** Licensees may use this file in accordance with the Qt Beta Version -** License Agreement, Agreement version 2.2 provided with the Software or, -** alternatively, in accordance with the terms contained in a written -** agreement between you and Nokia. -** -** GNU General Public License Usage -** -** Alternatively, this file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the packaging -** of this file. Please review the following information to ensure GNU -** General Public Licensing requirements will be met: -** -** http://www.fsf.org/licensing/licenses/info/GPLv2.html and -** http://www.gnu.org/copyleft/gpl.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt GPL Exception -** version 1.3, included in the file GPL_EXCEPTION.txt in this package. -** -***************************************************************************/ - -#ifndef QT4PRO_ENUMS_H -#define QT4PRO_ENUMS_H - -namespace Qt4ProjectManager { -namespace Internal { - -enum ProfileFormats { - ProfileVariableFormat, - ProfileFunctionFormat, - ProfileCommentFormat, - NumProfileFormats -}; - -} // namespace Internal -} // namespace Qt4ProjectManager - -#endif // QT4PRO_ENUMS_H diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 46d5bf363e9..f87e1df6b83 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -91,9 +91,6 @@ const char * const C_REMOVED_LINE = "RemovedLine"; const char * const C_DIFF_FILE = "DiffFile"; const char * const C_DIFF_LOCATION = "DiffLocation"; -const char * const C_VARIABLE = "Variable"; -const char * const C_FUNCTION = "Function"; - } // namespace Constants } // namespace TextEditor diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp index 2f9c597be65..5794935182c 100644 --- a/src/plugins/texteditor/texteditorsettings.cpp +++ b/src/plugins/texteditor/texteditorsettings.cpp @@ -91,10 +91,6 @@ TextEditorSettings::TextEditorSettings(Internal::TextEditorPlugin *plugin, formatDescriptions.push_back(FormatDescription(QLatin1String(C_DIFF_FILE), tr("Diff File"), Qt::black)); formatDescriptions.push_back(FormatDescription(QLatin1String(C_DIFF_LOCATION), tr("Diff Location"), Qt::green)); - // Pro file categories - formatDescriptions.push_back(FormatDescription(QLatin1String(C_VARIABLE), tr("Variable"), Qt::blue)); - formatDescriptions.push_back(FormatDescription(QLatin1String(C_FUNCTION), tr("Function"), Qt::green)); - m_fontSettingsPage = new FontSettingsPage(formatDescriptions, QLatin1String("TextEditor"), tr("Text Editor"), From 2c0a52098ee5195e1adc8e563db4858c0de24d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= Date: Thu, 8 Jan 2009 17:10:39 +0100 Subject: [PATCH 08/12] Whoops, forgot to remove an include --- src/plugins/qt4projectmanager/profilehighlighter.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/qt4projectmanager/profilehighlighter.h b/src/plugins/qt4projectmanager/profilehighlighter.h index 5d603cae160..bdbf9c60457 100644 --- a/src/plugins/qt4projectmanager/profilehighlighter.h +++ b/src/plugins/qt4projectmanager/profilehighlighter.h @@ -34,8 +34,6 @@ #ifndef PROFILEHIGHLIGHTER_H #define PROFILEHIGHLIGHTER_H -#include "qt4projectmanagerenums.h" - #include #include #include From 3f53aa16fba59619f5a9d78d549f6dfb63a989d8 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 8 Jan 2009 17:21:51 +0100 Subject: [PATCH 09/12] handle ! at least in visual line mode --- src/plugins/fakevim/handler.cpp | 110 ++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 20 deletions(-) diff --git a/src/plugins/fakevim/handler.cpp b/src/plugins/fakevim/handler.cpp index 3d3c228a12a..354401eb690 100644 --- a/src/plugins/fakevim/handler.cpp +++ b/src/plugins/fakevim/handler.cpp @@ -36,10 +36,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -90,6 +92,7 @@ enum SubMode RegisterSubMode, ChangeSubMode, DeleteSubMode, + FilterSubMode, ZSubMode, }; @@ -223,6 +226,7 @@ private: QString m_lastInsertion; // undo handling + void recordOperation(const EditOperation &op); void recordInsert(int position, const QString &data); void recordRemove(int position, const QString &data); void recordRemove(int position, int length); @@ -328,6 +332,18 @@ bool FakeVimHandler::Private::handleKey(int key, const QString &text) void FakeVimHandler::Private::finishMovement(const QString &dotCommand) { + if (m_submode == FilterSubMode) { + int beginLine = lineForPosition(m_tc.anchor()); + int endLine = lineForPosition(m_tc.position()); + m_tc.setPosition(qMin(m_tc.anchor(), m_tc.position()), MoveAnchor); + m_mode = ExMode; + m_commandBuffer = QString(".,+%1!").arg(qAbs(endLine - beginLine)); + m_commandHistory.append(QString()); + m_commandHistoryIndex = m_commandHistory.size() - 1; + updateMiniBuffer(); + return; + } + if (m_submode == ChangeSubMode) { if (!dotCommand.isEmpty()) m_dotCommand = "c" + dotCommand; @@ -409,12 +425,14 @@ void FakeVimHandler::Private::updateMiniBuffer() if (!m_currentMessage.isEmpty()) { msg = m_currentMessage; m_currentMessage.clear(); - } else if (m_visualMode == VisualCharMode) { - msg = "-- VISUAL --"; - } else if (m_visualMode == VisualLineMode) { - msg = "-- VISUAL LINE --"; - } else if (m_visualMode == VisualBlockMode) { - msg = "-- VISUAL BLOCK --"; + } else if (m_mode == CommandMode && m_visualMode != NoVisualMode) { + if (m_visualMode == VisualCharMode) { + msg = "-- VISUAL --"; + } else if (m_visualMode == VisualLineMode) { + msg = "-- VISUAL LINE --"; + } else if (m_visualMode == VisualBlockMode) { + msg = "-- VISUAL BLOCK --"; + } } else if (m_mode == InsertMode) { msg = "-- INSERT --"; } else { @@ -432,6 +450,8 @@ void FakeVimHandler::Private::updateMiniBuffer() msg += c; } } + if (!msg.isEmpty() && m_mode != CommandMode) + msg += '|'; // FIXME: Use a real "cursor" } emit q->commandBufferChanged(msg); @@ -533,6 +553,15 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) m_tc.movePosition(StartOfLine, KeepAnchor); m_tc.movePosition(Right, KeepAnchor, qMin(count(), rightDist()) - 1); finishMovement(); + } else if (key == '!' && m_visualMode == NoVisualMode) { + m_submode = FilterSubMode; + } else if (key == '!' && m_visualMode == VisualLineMode) { + m_mode = ExMode; + m_marks['>'] = m_tc.position(); + m_commandBuffer = "'<,'>!"; + m_commandHistory.append(QString()); + m_commandHistoryIndex = m_commandHistory.size() - 1; + updateMiniBuffer(); } else if (key == '"') { m_submode = RegisterSubMode; } else if (key == Key_Return) { @@ -744,7 +773,7 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) if (m_visualMode != NoVisualMode) leaveVisualMode(); } else { - qDebug() << "Ignored" << key << text; + qDebug() << "Ignored in command mode: " << key << text; return false; } return true; @@ -818,6 +847,11 @@ bool FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text else m_commandBuffer.chop(1); updateMiniBuffer(); + } else if (key == Key_Left) { + // FIXME: + if (!m_commandBuffer.isEmpty()) + m_commandBuffer.chop(1); + updateMiniBuffer(); } else if (key == Key_Return && m_mode == ExMode) { if (!m_commandBuffer.isEmpty()) { m_commandHistory.takeLast(); @@ -890,9 +924,9 @@ int FakeVimHandler::Private::readLineCode(QString &cmd) return cursorLineInDocument() + 1 + (n == -1 ? 1 : n); } if (c == '\'' && !cmd.isEmpty()) { - int pos = m_marks.value(cmd.at(0).unicode()); - qDebug() << " MARK: " << cmd.at(0) << pos << lineForPosition(pos); - if (!pos) { + int pos = m_marks.value(cmd.at(0).unicode(), -1); + //qDebug() << " MARK: " << cmd.at(0) << pos << lineForPosition(pos); + if (pos == -1) { showMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0))); return -1; } @@ -934,7 +968,8 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) QString cmd = cmd0; if (cmd.startsWith("%")) cmd = "1,$" + cmd.mid(1); - + + m_marks['>'] = m_tc.position(); int beginLine = -1; int endLine = -1; @@ -949,7 +984,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) endLine = line; } - qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0; + //qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0; static QRegExp reWrite("^w!?( (.*))?$"); static QRegExp reDelete("^d( (.*))?$"); @@ -1011,8 +1046,41 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) .arg(m_currentFileName).arg(data.count('\n')).arg(data.size()); enterCommandMode(); updateMiniBuffer(); + } else if (cmd.startsWith("!")) { + if (beginLine == -1) + beginLine = cursorLineInDocument(); + if (endLine == -1) + endLine = cursorLineInDocument(); + QTextCursor tc = selectRange(beginLine, endLine); + QString text = tc.selection().toPlainText(); + tc.removeSelectedText(); + QString command = cmd.mid(1).trimmed(); + QProcess proc; + proc.start(cmd.mid(1)); + proc.waitForStarted(); + proc.write(text.toUtf8()); + proc.closeWriteChannel(); + proc.waitForFinished(); + QString result = QString::fromUtf8(proc.readAllStandardOutput()); + m_tc.insertText(result); + leaveVisualMode(); + + m_tc.setPosition(positionForLine(beginLine)); + EditOperation op; + op.m_position = m_tc.position(); + op.m_from = text; + op.m_to = result; + recordOperation(op); + + m_commandBuffer = tr("%1 lines filtered").arg(text.count('\n')); + enterCommandMode(); + updateMiniBuffer(); + } else if (cmd == "red" || cmd == "redo") { // :redo + redo(); + enterCommandMode(); + updateMiniBuffer(); } else { - showMessage("E492: Not an editor command: " + cmd0); + showMessage("E492: Not an editor command: " + cmd0 + "(" + cmd + ")"); } } @@ -1303,13 +1371,18 @@ void FakeVimHandler::Private::redo() #endif } +void FakeVimHandler::Private::recordOperation(const EditOperation &op) +{ + m_undoStack.push(op); + m_redoStack.clear(); +} + void FakeVimHandler::Private::recordMove(int position, int nestedCount) { EditOperation op; op.m_position = position; op.m_itemCount = nestedCount; - m_undoStack.push(op); - m_redoStack.clear(); + recordOperation(op); } void FakeVimHandler::Private::recordInsert(int position, const QString &data) @@ -1317,8 +1390,7 @@ void FakeVimHandler::Private::recordInsert(int position, const QString &data) EditOperation op; op.m_position = position; op.m_to = data; - m_undoStack.push(op); - m_redoStack.clear(); + recordOperation(op); } void FakeVimHandler::Private::recordRemove(int position, int length) @@ -1334,8 +1406,7 @@ void FakeVimHandler::Private::recordRemove(int position, const QString &data) EditOperation op; op.m_position = position; op.m_from = data; - m_undoStack.push(op); - m_redoStack.clear(); + recordOperation(op); } void FakeVimHandler::Private::enterInsertMode() @@ -1411,7 +1482,6 @@ void FakeVimHandler::handleCommand(QWidget *widget, const QString &cmd) d->handleExCommand(cmd); } - void FakeVimHandler::quit() { d->quit(); From 5b500bec79417bd218a1b4df0e42f6fa510c8324 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 8 Jan 2009 17:40:27 +0100 Subject: [PATCH 10/12] code cleanup --- src/plugins/fakevim/handler.cpp | 131 +++++++++++++++++--------------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/src/plugins/fakevim/handler.cpp b/src/plugins/fakevim/handler.cpp index 354401eb690..af67103e70b 100644 --- a/src/plugins/fakevim/handler.cpp +++ b/src/plugins/fakevim/handler.cpp @@ -189,7 +189,8 @@ private: public: void enterInsertMode(); void enterCommandMode(); - void showMessage(const QString &msg); + void showRedMessage(const QString &msg); + void showBlackMessage(const QString &msg); void updateMiniBuffer(); void updateSelection(); void quit(); @@ -378,8 +379,10 @@ void FakeVimHandler::Private::updateSelection() QTextEdit::ExtraSelection sel; sel.cursor = m_tc; sel.format = m_tc.blockCharFormat(); - sel.format.setFontWeight(QFont::Bold); - sel.format.setFontUnderline(true); + //sel.format.setFontWeight(QFont::Bold); + //sel.format.setFontUnderline(true); + sel.format.setForeground(Qt::white); + sel.format.setBackground(Qt::black); int cursorPos = m_tc.position(); int anchorPos = m_marks['<']; //qDebug() << "POS: " << cursorPos << " ANCHOR: " << anchorPos; @@ -451,7 +454,7 @@ void FakeVimHandler::Private::updateMiniBuffer() } } if (!msg.isEmpty() && m_mode != CommandMode) - msg += '|'; // FIXME: Use a real "cursor" + msg += QChar(10073); // '|'; // FIXME: Use a real "cursor" } emit q->commandBufferChanged(msg); @@ -470,13 +473,20 @@ void FakeVimHandler::Private::updateMiniBuffer() emit q->statusDataChanged(status); } -void FakeVimHandler::Private::showMessage(const QString &msg) +void FakeVimHandler::Private::showRedMessage(const QString &msg) { //qDebug() << "MSG: " << msg; m_currentMessage = msg; updateMiniBuffer(); } +void FakeVimHandler::Private::showBlackMessage(const QString &msg) +{ + //qDebug() << "MSG: " << msg; + m_commandBuffer = msg; + updateMiniBuffer(); +} + bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) { Q_UNUSED(text) @@ -519,7 +529,7 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) moveToFirstNonBlankOnLine(); finishMovement(); } else { - showMessage(tr("E20: Mark '%1' not set").arg(text)); + showRedMessage(tr("E20: Mark '%1' not set").arg(text)); } m_subsubmode = NoSubSubMode; } else if (key >= '0' && key <= '9') { @@ -872,26 +882,22 @@ bool FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text // takes only matching entires in the history into account. if (m_searchHistoryIndex > 0) { --m_searchHistoryIndex; - m_commandBuffer = m_searchHistory.at(m_searchHistoryIndex); - updateMiniBuffer(); + showBlackMessage(m_searchHistory.at(m_searchHistoryIndex)); } } else if (key == Key_Up && m_mode == ExMode) { if (m_commandHistoryIndex > 0) { --m_commandHistoryIndex; - m_commandBuffer = m_commandHistory.at(m_commandHistoryIndex); - updateMiniBuffer(); + showBlackMessage(m_commandHistory.at(m_commandHistoryIndex)); } } else if (key == Key_Down && isSearchMode()) { if (m_searchHistoryIndex < m_searchHistory.size() - 1) { ++m_searchHistoryIndex; - m_commandBuffer = m_searchHistory.at(m_searchHistoryIndex); - updateMiniBuffer(); + showBlackMessage(m_searchHistory.at(m_searchHistoryIndex)); } } else if (key == Key_Down && m_mode == ExMode) { if (m_commandHistoryIndex < m_commandHistory.size() - 1) { ++m_commandHistoryIndex; - m_commandBuffer = m_commandHistory.at(m_commandHistoryIndex); - updateMiniBuffer(); + showBlackMessage(m_commandHistory.at(m_commandHistoryIndex)); } } else if (key == Key_Tab) { m_commandBuffer += QChar(9); @@ -927,7 +933,7 @@ int FakeVimHandler::Private::readLineCode(QString &cmd) int pos = m_marks.value(cmd.at(0).unicode(), -1); //qDebug() << " MARK: " << cmd.at(0) << pos << lineForPosition(pos); if (pos == -1) { - showMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0))); + showRedMessage(tr("E20: Mark '%1' not set").arg(cmd.at(0))); return -1; } cmd = cmd.mid(1); @@ -991,7 +997,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) if (cmd.isEmpty()) { m_tc.setPosition(positionForLine(beginLine)); - showMessage(QString()); + showBlackMessage(QString()); } else if (cmd == "q!" || cmd == "q") { // :q quit(); } else if (reDelete.indexIn(cmd) != -1) { // :d @@ -1019,7 +1025,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) QFile file(fileName); bool exists = file.exists(); if (exists && !forced && !noArgs) { - showMessage(tr("File '%1' exists (add ! to override)").arg(fileName)); + showRedMessage(tr("File '%1' exists (add ! to override)").arg(fileName)); } else if (file.open(QIODevice::ReadWrite)) { QTextCursor tc = selectRange(beginLine, endLine); qDebug() << "ANCHOR: " << tc.position() << tc.anchor() @@ -1028,12 +1034,11 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) file.close(); file.open(QIODevice::ReadOnly); QByteArray ba = file.readAll(); - m_commandBuffer = QString("\"%1\" %2 %3L, %4C written") + showBlackMessage(tr("\"%1\" %2 %3L, %4C written") .arg(fileName).arg(exists ? " " : " [New] ") - .arg(ba.count('\n')).arg(ba.size()); - updateMiniBuffer(); + .arg(ba.count('\n')).arg(ba.size())); } else { - showMessage(tr("Cannot open file '%1' for reading").arg(fileName)); + showRedMessage(tr("Cannot open file '%1' for reading").arg(fileName)); } } else if (cmd.startsWith("r ")) { // :r m_currentFileName = cmd.mid(2); @@ -1042,10 +1047,9 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) QTextStream ts(&file); QString data = ts.readAll(); EDITOR(setPlainText(data)); - m_commandBuffer = QString("\"%1\" %2L, %3C") - .arg(m_currentFileName).arg(data.count('\n')).arg(data.size()); enterCommandMode(); - updateMiniBuffer(); + showBlackMessage(tr("\"%1\" %2L, %3C") + .arg(m_currentFileName).arg(data.count('\n')).arg(data.size())); } else if (cmd.startsWith("!")) { if (beginLine == -1) beginLine = cursorLineInDocument(); @@ -1072,15 +1076,14 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) op.m_to = result; recordOperation(op); - m_commandBuffer = tr("%1 lines filtered").arg(text.count('\n')); enterCommandMode(); - updateMiniBuffer(); + showBlackMessage(tr("%1 lines filtered").arg(text.count('\n'))); } else if (cmd == "red" || cmd == "redo") { // :redo redo(); enterCommandMode(); updateMiniBuffer(); } else { - showMessage("E492: Not an editor command: " + cmd0 + "(" + cmd + ")"); + showRedMessage("E492: Not an editor command: " + cmd0); } } @@ -1110,9 +1113,9 @@ void FakeVimHandler::Private::search(const QString &needle, bool forward) // the qMax seems to be needed for QPlainTextEdit only m_tc.movePosition(Left, MoveAnchor, qMax(1, needle.size() - 1)); if (forward) - showMessage("search hit BOTTOM, continuing at TOP"); + showRedMessage("search hit BOTTOM, continuing at TOP"); else - showMessage("search hit TOP, continuing at BOTTOM"); + showRedMessage("search hit TOP, continuing at BOTTOM"); return; } @@ -1324,24 +1327,26 @@ void FakeVimHandler::Private::undo() #if 0 EDITOR(undo()); #else - if (m_undoStack.isEmpty()) - return; - EditOperation op = m_undoStack.pop(); - //qDebug() << "UNDO " << op; - if (op.m_itemCount > 0) { - for (int i = op.m_itemCount; --i >= 0; ) - undo(); + if (m_undoStack.isEmpty()) { + showBlackMessage(tr("Already at oldest change")); } else { - m_tc.setPosition(op.m_position, MoveAnchor); - if (!op.m_to.isEmpty()) { - m_tc.setPosition(op.m_position + op.m_to.size(), KeepAnchor); - m_tc.deleteChar(); + EditOperation op = m_undoStack.pop(); + //qDebug() << "UNDO " << op; + if (op.m_itemCount > 0) { + for (int i = op.m_itemCount; --i >= 0; ) + undo(); + } else { + m_tc.setPosition(op.m_position, MoveAnchor); + if (!op.m_to.isEmpty()) { + m_tc.setPosition(op.m_position + op.m_to.size(), KeepAnchor); + m_tc.deleteChar(); + } + if (!op.m_from.isEmpty()) + m_tc.insertText(op.m_from); + m_tc.setPosition(op.m_position, MoveAnchor); } - if (!op.m_from.isEmpty()) - m_tc.insertText(op.m_from); - m_tc.setPosition(op.m_position, MoveAnchor); + m_redoStack.push(op); } - m_redoStack.push(op); #endif } @@ -1350,24 +1355,26 @@ void FakeVimHandler::Private::redo() #if 0 EDITOR(redo()); #else - if (m_redoStack.isEmpty()) - return; - EditOperation op = m_redoStack.pop(); - //qDebug() << "REDO " << op; - if (op.m_itemCount > 0) { - for (int i = op.m_itemCount; --i >= 0; ) - redo(); + if (m_redoStack.isEmpty()) { + showBlackMessage(tr("Already at newest change")); } else { - m_tc.setPosition(op.m_position, MoveAnchor); - if (!op.m_from.isEmpty()) { - m_tc.setPosition(op.m_position + op.m_from.size(), KeepAnchor); - m_tc.deleteChar(); + EditOperation op = m_redoStack.pop(); + //qDebug() << "REDO " << op; + if (op.m_itemCount > 0) { + for (int i = op.m_itemCount; --i >= 0; ) + redo(); + } else { + m_tc.setPosition(op.m_position, MoveAnchor); + if (!op.m_from.isEmpty()) { + m_tc.setPosition(op.m_position + op.m_from.size(), KeepAnchor); + m_tc.deleteChar(); + } + if (!op.m_to.isEmpty()) + m_tc.insertText(op.m_to); + m_tc.setPosition(op.m_position, MoveAnchor); } - if (!op.m_to.isEmpty()) - m_tc.insertText(op.m_to); - m_tc.setPosition(op.m_position, MoveAnchor); + m_undoStack.push(op); } - m_undoStack.push(op); #endif } @@ -1425,7 +1432,7 @@ void FakeVimHandler::Private::enterCommandMode() void FakeVimHandler::Private::quit() { - showMessage(QString()); + showBlackMessage(QString()); EDITOR(setOverwriteMode(false)); q->quitRequested(editor()); } @@ -1464,13 +1471,13 @@ void FakeVimHandler::addWidget(QWidget *widget) //ed->setCursorWidth(QFontMetrics(ed->font()).width(QChar('x'))); ed->setLineWrapMode(QPlainTextEdit::NoWrap); } - d->showMessage("vi emulation mode. Hit :q to quit"); + d->showBlackMessage("vi emulation mode. Hit :q to quit"); d->updateMiniBuffer(); } void FakeVimHandler::removeWidget(QWidget *widget) { - d->showMessage(QString()); + d->showBlackMessage(QString()); d->updateMiniBuffer(); widget->removeEventFilter(this); } From c8c362aa7d53692cb642ef706ece9303674f9a5f Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 8 Jan 2009 17:58:42 +0100 Subject: [PATCH 11/12] fix some cases where deletions were not recorded in the undo stack --- src/plugins/fakevim/handler.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/plugins/fakevim/handler.cpp b/src/plugins/fakevim/handler.cpp index af67103e70b..5103db105c8 100644 --- a/src/plugins/fakevim/handler.cpp +++ b/src/plugins/fakevim/handler.cpp @@ -232,6 +232,7 @@ private: void recordRemove(int position, const QString &data); void recordRemove(int position, int length); void recordMove(int position, int nestedCount); + void removeSelectedText(QTextCursor &tc); void undo(); void redo(); QStack m_undoStack; @@ -349,7 +350,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand) if (!dotCommand.isEmpty()) m_dotCommand = "c" + dotCommand; m_registers[m_register] = m_tc.selectedText(); - m_tc.removeSelectedText(); + removeSelectedText(m_tc); m_mode = InsertMode; m_submode = NoSubMode; } else if (m_submode == DeleteSubMode) { @@ -357,7 +358,7 @@ void FakeVimHandler::Private::finishMovement(const QString &dotCommand) m_dotCommand = "d" + dotCommand; recordRemove(qMin(m_tc.position(), m_tc.anchor()), m_tc.selectedText()); m_registers[m_register] = m_tc.selectedText(); - m_tc.removeSelectedText(); + removeSelectedText(m_tc); m_submode = NoSubMode; if (atEol()) m_tc.movePosition(Left, MoveAnchor, 1); @@ -620,7 +621,7 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) int beginLine = lineForPosition(m_marks['<']); int endLine = lineForPosition(m_marks['>']); m_tc = selectRange(beginLine, endLine); - m_tc.removeSelectedText(); + removeSelectedText(m_tc); } else if (key == 'D') { m_submode = DeleteSubMode; m_tc.movePosition(Down, KeepAnchor, qMax(count() - 1, 0)); @@ -734,6 +735,10 @@ bool FakeVimHandler::Private::handleCommandMode(int key, const QString &text) m_subsubdata = key; } else if (key == 'u') { undo(); + } else if (key == 'U') { + // FIXME: this is non-vim, but as Ctrl-R is taken globally + // we have a substitute here + redo(); } else if (key == 'v') { enterVisualMode(VisualCharMode); } else if (key == 'V') { @@ -1071,6 +1076,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0) m_tc.setPosition(positionForLine(beginLine)); EditOperation op; + // FIXME: broken for "upward selection" op.m_position = m_tc.position(); op.m_from = text; op.m_to = result; @@ -1346,6 +1352,7 @@ void FakeVimHandler::Private::undo() m_tc.setPosition(op.m_position, MoveAnchor); } m_redoStack.push(op); + showBlackMessage(QString()); } #endif } @@ -1374,10 +1381,20 @@ void FakeVimHandler::Private::redo() m_tc.setPosition(op.m_position, MoveAnchor); } m_undoStack.push(op); + showBlackMessage(QString()); } #endif } +void FakeVimHandler::Private::removeSelectedText(QTextCursor &tc) +{ + EditOperation op; + op.m_position = qMin(tc.position(), tc.anchor()); + op.m_from = tc.selection().toPlainText(); + recordOperation(op); + tc.removeSelectedText(); +} + void FakeVimHandler::Private::recordOperation(const EditOperation &op) { m_undoStack.push(op); From c5f9695fe1ac1606fe82b6a2b75bafa454a400c6 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Thu, 8 Jan 2009 18:05:33 +0100 Subject: [PATCH 12/12] More work on ObjC++ support. --- shared/cplusplus/Parser.cpp | 165 +++++++++++++++++++++++++++++++++--- shared/cplusplus/Parser.h | 17 +++- 2 files changed, 166 insertions(+), 16 deletions(-) diff --git a/shared/cplusplus/Parser.cpp b/shared/cplusplus/Parser.cpp index c1e48f233f4..67fed9e0118 100644 --- a/shared/cplusplus/Parser.cpp +++ b/shared/cplusplus/Parser.cpp @@ -68,6 +68,7 @@ Parser::Parser(TranslationUnit *unit) _tokenIndex(1), _templateArguments(0), _qtMocRunEnabled(false), + _objcEnabled(false), _inFunctionBody(false) { } @@ -2532,7 +2533,16 @@ bool Parser::parsePrimaryExpression(ExpressionAST *&node) case T_SLOT: return parseQtMethod(node); + case T_AT_ENCODE: + case T_AT_PROTOCOL: + case T_AT_SELECTOR: + case T_AT_STRING_LITERAL: + return parseObjCExpression(node); + default: { + if (_objcEnabled && LA() == T_LBRACKET) + return parseObjCExpression(node); + unsigned startOfName = cursor(); NameAST *name = 0; if (parseName(name)) { @@ -3296,17 +3306,17 @@ bool Parser::parseObjCClassDeclaration(DeclarationAST *&node) return true; } -bool Parser::parseObjCInterfaceDeclaration(DeclarationAST *&node) +bool Parser::parseObjCInterfaceDeclaration(DeclarationAST *&) { if (LA() != T_AT_INTERFACE) return false; - unsigned interface_token = consumeToken(); + /*unsigned interface_token = */ consumeToken(); unsigned interface_name_token = 0; match(T_IDENTIFIER, &interface_name_token); if (LA() == T_LPAREN) { // category interface - unsigned lparen_token = consumeToken(); + /*unsigned lparen_token = */ consumeToken(); unsigned catagory_name_token = 0; if (LA() == T_IDENTIFIER) catagory_name_token = consumeToken(); @@ -3335,27 +3345,27 @@ bool Parser::parseObjCInterfaceDeclaration(DeclarationAST *&node) return false; } -bool Parser::parseObjCProtocolDeclaration(DeclarationAST *&node) +bool Parser::parseObjCProtocolDeclaration(DeclarationAST *&) { return false; } -bool Parser::parseObjCEndDeclaration(DeclarationAST *&node) +bool Parser::parseObjCEndDeclaration(DeclarationAST *&) { return false; } -bool Parser::parseObjCAliasDeclaration(DeclarationAST *&node) +bool Parser::parseObjCAliasDeclaration(DeclarationAST *&) { return false; } -bool Parser::parseObjCPropertySynthesize(DeclarationAST *&node) +bool Parser::parseObjCPropertySynthesize(DeclarationAST *&) { return false; } -bool Parser::parseObjCPropertyDynamic(DeclarationAST *&node) +bool Parser::parseObjCPropertyDynamic(DeclarationAST *&) { return false; } @@ -3419,15 +3429,16 @@ bool Parser::parseObjCInterfaceMemberDeclaration() default: { DeclarationAST *declaration = 0; - parseDeclaration(declaration); + if (parseDeclaration(declaration)) + return true; } // default } // switch - return true; + return false; } -bool Parser::parseObjCPropertyDeclaration(DeclarationAST *&ast) +bool Parser::parseObjCPropertyDeclaration(DeclarationAST *&) { return false; } @@ -3438,8 +3449,7 @@ bool Parser::parseObjCMethodPrototype() return false; // instance or class method? - unsigned method_type_token = consumeToken(); - + /*unsigned method_type_token = */ consumeToken(); SpecifierAST *attributes = 0, **attr = &attributes; while (parseAttributeSpecifier(*attr)) @@ -3448,6 +3458,135 @@ bool Parser::parseObjCMethodPrototype() return false; } +bool Parser::parseObjCExpression(ExpressionAST *&node) +{ + switch (LA()) { + case T_LBRACKET: + return parseObjCMessageExpression(node); + case T_AT_STRING_LITERAL: + return parseObjCStringLiteral(node); + + case T_AT_ENCODE: + return parseObjCEncodeExpression(node); + + case T_AT_PROTOCOL: + return parseObjCProtocolExpression(node); + + case T_AT_SELECTOR: + return parseObjCSelectorExpression(node); + } + return false; +} + +bool Parser::parseObjCMessageExpression(ExpressionAST *&) +{ + if (LA() != T_LBRACKET) + return false; + + /*unsigned lbracket_token = */ consumeToken(); + ExpressionAST *receiver = 0; + parseObjCMessageReceiver(receiver); + parseObjCMessageArguments(); + unsigned rbracket_token = 0; + match(T_RBRACKET, &rbracket_token); + return true; +} + +bool Parser::parseObjCStringLiteral(ExpressionAST *&) +{ + if (LA() != T_AT_STRING_LITERAL) + return false; + + do { + consumeToken(); + } while (LA() == T_AT_STRING_LITERAL); + + return true; +} + +bool Parser::parseObjCEncodeExpression(ExpressionAST *&) +{ + if (LA() != T_AT_ENCODE) + return false; + + /*unsigned encode_token = */ consumeToken(); + unsigned lparen_token = 0, rparen_token = 0; + match(T_LPAREN, &lparen_token); + SpecifierAST *type_specifier = 0; + parseSimpleTypeSpecifier(type_specifier); + match(T_RPAREN, &rparen_token); + return true; +} + +bool Parser::parseObjCProtocolExpression(ExpressionAST *&) +{ + if (LA() != T_AT_PROTOCOL) + return false; + + /*unsigned protocol_token = */ consumeToken(); + unsigned protocol_name_token = 0, lparen_token = 0, rparen_token = 0; + match(T_LPAREN, &lparen_token); + match(T_IDENTIFIER, &protocol_name_token); + match(T_RPAREN, &rparen_token); + return true; +} + +bool Parser::parseObjCSelectorExpression(ExpressionAST *&) +{ + if (LA() != T_AT_SELECTOR) + return false; + + /*unsigned selector_token = */ consumeToken(); + unsigned lparen_token = 0, rparen_token = 0; + match(T_LPAREN, &lparen_token); + while (LA(1) == T_IDENTIFIER && LA(2) == T_COLON) { + /*unsigned identifier_token = */ consumeToken(); + /*unsigned colon_token = */ consumeToken(); + } + match(T_RPAREN, &rparen_token); + return true; +} + +bool Parser::parseObjCMessageReceiver(ExpressionAST *&node) +{ + // ### expression or simple-type-specifier. + return parseExpression(node); +} + +bool Parser::parseObjCMessageArguments() +{ + if (LA() != T_IDENTIFIER && LA() != T_COLON) + return false; + + unsigned selector_name_token = 0; + + if (LA() == T_IDENTIFIER) + selector_name_token = consumeToken(); + + if (LA() == T_COLON) { + /*unsigned colon_token = */ consumeToken(); + + ExpressionAST *expr = 0; + parseAssignmentExpression(expr); + + while ((LA() == T_IDENTIFIER && LA(2) == T_COLON) || LA() == T_COLON) { + if (LA() == T_IDENTIFIER) + consumeToken(); + + if (LA() == T_COLON) + consumeToken(); + + parseAssignmentExpression(expr); + } + + while (LA() == T_COMMA) { + consumeToken(); + parseAssignmentExpression(expr); + } + } + + return true; +} CPLUSPLUS_END_NAMESPACE diff --git a/shared/cplusplus/Parser.h b/shared/cplusplus/Parser.h index 1eac8ce7652..8bde1cccc46 100644 --- a/shared/cplusplus/Parser.h +++ b/shared/cplusplus/Parser.h @@ -214,13 +214,23 @@ public: bool parseObjCIdentifierList(IdentifierListAST *&node); - bool parseObjCPropertyDeclaration(DeclarationAST *&ast); + bool parseObjCPropertyDeclaration(DeclarationAST *&node); bool parseObjCProtocolRefs(); bool parseObjCClassInstanceVariables(); bool parseObjCInterfaceMemberDeclaration(); bool parseObjCInterfaceDeclList(); bool parseObjCMethodPrototype(); + bool parseObjCExpression(ExpressionAST *&node); + bool parseObjCMessageExpression(ExpressionAST *&node); + bool parseObjCStringLiteral(ExpressionAST *&node); + bool parseObjCEncodeExpression(ExpressionAST *&node); + bool parseObjCProtocolExpression(ExpressionAST *&node); + bool parseObjCSelectorExpression(ExpressionAST *&node); + + bool parseObjCMessageReceiver(ExpressionAST *&node); + bool parseObjCMessageArguments(); + // Qt MOC run bool parseQtMethod(ExpressionAST *&node); @@ -245,8 +255,8 @@ private: bool switchTemplateArguments(bool templateArguments); bool blockErrors(bool block); - inline const Token &tok() const - { return _translationUnit->tokenAt(_tokenIndex); } + inline const Token &tok(int i = 1) const + { return _translationUnit->tokenAt(_tokenIndex + i - 1); } inline int LA(int n = 1) const { return _translationUnit->tokenKind(_tokenIndex + n - 1); } @@ -267,6 +277,7 @@ private: unsigned _tokenIndex; bool _templateArguments: 1; bool _qtMocRunEnabled: 1; + bool _objcEnabled: 1; bool _inFunctionBody: 1; private: