forked from qt-creator/qt-creator
CPlusPlus: Make (sub-)languague selection more generic
Change-Id: I4e2df6992b446adec662ab07671acd41715e41fd Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -45,9 +45,14 @@ BackwardsScanner::BackwardsScanner(const QTextCursor &cursor,
|
||||
, _block(cursor.block())
|
||||
, _maxBlockCount(maxBlockCount)
|
||||
{
|
||||
_tokenize.setQtMocRunEnabled(true);
|
||||
// FIXME: Why these defaults?
|
||||
LanguageFeatures features;
|
||||
features.qtMocRunEnabled = true;
|
||||
features.qtEnabled = true;
|
||||
features.qtKeywordsEnabled = true;
|
||||
features.objCEnabled = true;
|
||||
_tokenize.setLanguageFeatures(features);
|
||||
_tokenize.setSkipComments(skipComments);
|
||||
_tokenize.setObjCEnabled(true);
|
||||
_text = _block.text().left(cursor.position() - cursor.block().position());
|
||||
|
||||
if (! suffix.isEmpty())
|
||||
|
||||
@@ -284,10 +284,14 @@ Document::Document(const QString &fileName)
|
||||
const QByteArray localFileName = fileName.toUtf8();
|
||||
const StringLiteral *fileId = _control->stringLiteral(localFileName.constData(),
|
||||
localFileName.size());
|
||||
LanguageFeatures features;
|
||||
features.qtEnabled = true;
|
||||
features.qtMocRunEnabled = true;
|
||||
features.qtKeywordsEnabled = true;
|
||||
features.cxx11Enabled = true;
|
||||
features.objCEnabled = true;
|
||||
_translationUnit = new TranslationUnit(_control, fileId);
|
||||
_translationUnit->setQtMocRunEnabled(true);
|
||||
_translationUnit->setCxxOxEnabled(true);
|
||||
_translationUnit->setObjCEnabled(true);
|
||||
_translationUnit->setLanguageFeatures(features);
|
||||
(void) _control->switchTranslationUnit(_translationUnit);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,46 +40,12 @@ using namespace CPlusPlus;
|
||||
SimpleLexer::SimpleLexer()
|
||||
: _lastState(0),
|
||||
_skipComments(false),
|
||||
_qtMocRunEnabled(true),
|
||||
_objCEnabled(false),
|
||||
_endedJoined(false),
|
||||
_cxx0xEnabled(false)
|
||||
{
|
||||
}
|
||||
_endedJoined(false)
|
||||
{}
|
||||
|
||||
SimpleLexer::~SimpleLexer()
|
||||
{ }
|
||||
|
||||
bool SimpleLexer::qtMocRunEnabled() const
|
||||
{
|
||||
return _qtMocRunEnabled;
|
||||
}
|
||||
|
||||
void SimpleLexer::setQtMocRunEnabled(bool enabled)
|
||||
{
|
||||
_qtMocRunEnabled = enabled;
|
||||
}
|
||||
|
||||
bool SimpleLexer::objCEnabled() const
|
||||
{
|
||||
return _objCEnabled;
|
||||
}
|
||||
|
||||
void SimpleLexer::setObjCEnabled(bool onoff)
|
||||
{
|
||||
_objCEnabled = onoff;
|
||||
}
|
||||
|
||||
bool SimpleLexer::cxx0xEnabled() const
|
||||
{
|
||||
return _cxx0xEnabled;
|
||||
}
|
||||
|
||||
void SimpleLexer::setCxx0xEnabled(bool enabled)
|
||||
{
|
||||
_cxx0xEnabled = enabled;
|
||||
}
|
||||
|
||||
bool SimpleLexer::skipComments() const
|
||||
{
|
||||
return _skipComments;
|
||||
@@ -104,11 +70,8 @@ QList<Token> SimpleLexer::operator()(const QString &text, int state)
|
||||
const char *lastChar = firstChar + bytes.size();
|
||||
|
||||
Lexer lex(firstChar, lastChar);
|
||||
lex.setQtMocRunEnabled(_qtMocRunEnabled);
|
||||
lex.setObjCEnabled(_objCEnabled);
|
||||
lex.setLanguageFeatures(_languageFeatures);
|
||||
lex.setStartWithNewline(true);
|
||||
lex.setObjCEnabled(_objCEnabled);
|
||||
lex.setCxxOxEnabled(_cxx0xEnabled);
|
||||
|
||||
if (! _skipComments)
|
||||
lex.setScanCommentTokens(true);
|
||||
@@ -137,7 +100,7 @@ QList<Token> SimpleLexer::operator()(const QString &text, int state)
|
||||
else if (inPreproc && tokens.size() == 1 && tk.is(T_IDENTIFIER) &&
|
||||
spell == QLatin1String("include_next"))
|
||||
lex.setScanAngleStringLiteralTokens(true);
|
||||
else if (_objCEnabled
|
||||
else if (_languageFeatures.objCEnabled
|
||||
&& inPreproc && tokens.size() == 1 && tk.is(T_IDENTIFIER) &&
|
||||
spell == QLatin1String("import"))
|
||||
lex.setScanAngleStringLiteralTokens(true);
|
||||
@@ -165,8 +128,13 @@ Token SimpleLexer::tokenAt(const QString &text,
|
||||
int state,
|
||||
bool qtMocRunEnabled)
|
||||
{
|
||||
// FIXME: Check default values.
|
||||
LanguageFeatures features;
|
||||
features.qtMocRunEnabled = qtMocRunEnabled;
|
||||
features.qtEnabled = qtMocRunEnabled;
|
||||
features.qtKeywordsEnabled = qtMocRunEnabled;
|
||||
SimpleLexer tokenize;
|
||||
tokenize.setQtMocRunEnabled(qtMocRunEnabled);
|
||||
tokenize.setLanguageFeatures(features);
|
||||
const QList<Token> tokens = tokenize(text, state);
|
||||
const int tokenIdx = tokenAt(tokens, offset);
|
||||
return (tokenIdx == -1) ? Token() : tokens.at(tokenIdx);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#define CPLUSPLUS_SIMPLELEXER_H
|
||||
|
||||
#include <cplusplus/CPlusPlusForwardDeclarations.h>
|
||||
#include <cplusplus/Token.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
@@ -48,14 +49,8 @@ public:
|
||||
bool skipComments() const;
|
||||
void setSkipComments(bool skipComments);
|
||||
|
||||
bool qtMocRunEnabled() const;
|
||||
void setQtMocRunEnabled(bool enabled);
|
||||
|
||||
bool objCEnabled() const;
|
||||
void setObjCEnabled(bool onoff);
|
||||
|
||||
bool cxx0xEnabled() const;
|
||||
void setCxx0xEnabled(bool enabled);
|
||||
LanguageFeatures languageFeatures() const { return _languageFeatures; }
|
||||
void setLanguageFeatures(LanguageFeatures features) { _languageFeatures = features; }
|
||||
|
||||
bool endedJoined() const;
|
||||
|
||||
@@ -74,11 +69,9 @@ public:
|
||||
|
||||
private:
|
||||
int _lastState;
|
||||
LanguageFeatures _languageFeatures;
|
||||
bool _skipComments: 1;
|
||||
bool _qtMocRunEnabled: 1;
|
||||
bool _objCEnabled: 1;
|
||||
bool _endedJoined: 1;
|
||||
bool _cxx0xEnabled: 1;
|
||||
};
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
||||
Reference in New Issue
Block a user