C++: Accept language features in BackwardsScanner et al

Change-Id: Id97ca27fa909979573efca12dc0cd14b28eacd17
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-02-26 09:14:38 +02:00
committed by Orgad Shaneh
parent 1a37605f91
commit d63624afe0
15 changed files with 48 additions and 47 deletions

View File

@@ -38,6 +38,7 @@
using namespace CPlusPlus;
BackwardsScanner::BackwardsScanner(const QTextCursor &cursor,
const LanguageFeatures &languageFeatures,
int maxBlockCount,
const QString &suffix,
bool skipComments)
@@ -46,13 +47,7 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor,
, _block(cursor.block())
, _maxBlockCount(maxBlockCount)
{
// FIXME: Why these defaults?
LanguageFeatures features;
features.qtMocRunEnabled = true;
features.qtEnabled = true;
features.qtKeywordsEnabled = true;
features.objCEnabled = true;
_tokenize.setLanguageFeatures(features);
_tokenize.setLanguageFeatures(languageFeatures);
_tokenize.setSkipComments(skipComments);
_text = _block.text().left(cursor.position() - cursor.block().position());

View File

@@ -43,10 +43,11 @@ class CPLUSPLUS_EXPORT BackwardsScanner
enum { MAX_BLOCK_COUNT = 10 };
public:
explicit BackwardsScanner(const QTextCursor &cursor,
int maxBlockCount = MAX_BLOCK_COUNT,
const QString &suffix = QString(),
bool skipComments = true);
BackwardsScanner(const QTextCursor &cursor,
const LanguageFeatures &languageFeatures,
int maxBlockCount = MAX_BLOCK_COUNT,
const QString &suffix = QString(),
bool skipComments = true);
int startToken() const;

View File

@@ -40,8 +40,9 @@
using namespace CPlusPlus;
ExpressionUnderCursor::ExpressionUnderCursor()
ExpressionUnderCursor::ExpressionUnderCursor(const LanguageFeatures &languageFeatures)
: _jumpedComma(false)
, _languageFeatures(languageFeatures)
{ }
int ExpressionUnderCursor::startOfExpression(BackwardsScanner &tk, int index)
@@ -243,7 +244,7 @@ bool ExpressionUnderCursor::isAccessToken(const Token &tk)
QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
{
BackwardsScanner scanner(cursor);
BackwardsScanner scanner(cursor, _languageFeatures);
_jumpedComma = false;
@@ -257,7 +258,7 @@ QString ExpressionUnderCursor::operator()(const QTextCursor &cursor)
int ExpressionUnderCursor::startOfFunctionCall(const QTextCursor &cursor) const
{
BackwardsScanner scanner(cursor);
BackwardsScanner scanner(cursor, _languageFeatures);
int index = scanner.startToken();

View File

@@ -32,6 +32,7 @@
#define CPLUSPLUS_EXPRESSIONUNDERCURSOR_H
#include <cplusplus/CPlusPlusForwardDeclarations.h>
#include <cplusplus/Token.h>
#include <QList>
@@ -47,7 +48,7 @@ class BackwardsScanner;
class CPLUSPLUS_EXPORT ExpressionUnderCursor
{
public:
ExpressionUnderCursor();
ExpressionUnderCursor(const LanguageFeatures &languageFeatures);
QString operator()(const QTextCursor &cursor);
int startOfFunctionCall(const QTextCursor &cursor) const;
@@ -59,6 +60,7 @@ private:
private:
bool _jumpedComma;
LanguageFeatures _languageFeatures;
};
} // namespace CPlusPlus

View File

@@ -154,7 +154,8 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
if (text.isEmpty() || !shouldInsertMatchingText(la))
return QString();
BackwardsScanner tk(tc, MAX_NUM_LINES, textToProcess.left(*skippedChars));
BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES,
textToProcess.left(*skippedChars));
const int startToken = tk.startToken();
int index = startToken;
@@ -215,7 +216,7 @@ static bool shouldInsertNewline(const QTextCursor &tc)
QString MatchingText::insertParagraphSeparator(const QTextCursor &tc)
{
BackwardsScanner tk(tc, MAX_NUM_LINES);
BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES);
int index = tk.startToken();
if (tk[index - 1].isNot(T_LBRACE))