forked from qt-creator/qt-creator
Preprocessor Enginge: fix bug in pp-engine.cpp
Preprocessor variables __LINE__,__FILE__,__TIME__,__DATE__ where destroying the following systems when affected variables were standing within the same line with those variables: * highlighting * refactoring * local renaming Task-number: QTCREATORBUG-8036 Change-Id: I1a4b919d15812872ca5a8e63b1031ec1ab144c22 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
e4d800ad4a
commit
1d834c1126
@@ -906,49 +906,7 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
|
||||
{
|
||||
ScopedBoolSwap s(m_state.m_inPreprocessorDirective, true);
|
||||
|
||||
static const QByteArray ppLine("__LINE__");
|
||||
static const QByteArray ppFile("__FILE__");
|
||||
static const QByteArray ppDate("__DATE__");
|
||||
static const QByteArray ppTime("__TIME__");
|
||||
|
||||
ByteArrayRef macroNameRef = tk->asByteArrayRef();
|
||||
|
||||
if (macroNameRef.size() == 8
|
||||
&& macroNameRef[0] == '_'
|
||||
&& macroNameRef[1] == '_') {
|
||||
PPToken newTk;
|
||||
if (macroNameRef == ppLine) {
|
||||
QByteArray txt = QByteArray::number(tk->lineno);
|
||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||
} else if (macroNameRef == ppFile) {
|
||||
QByteArray txt;
|
||||
txt.append('"');
|
||||
txt.append(m_env->currentFileUtf8);
|
||||
txt.append('"');
|
||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||
} else if (macroNameRef == ppDate) {
|
||||
QByteArray txt;
|
||||
txt.append('"');
|
||||
txt.append(QDate::currentDate().toString().toUtf8());
|
||||
txt.append('"');
|
||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||
} else if (macroNameRef == ppTime) {
|
||||
QByteArray txt;
|
||||
txt.append('"');
|
||||
txt.append(QTime::currentTime().toString().toUtf8());
|
||||
txt.append('"');
|
||||
newTk = generateToken(T_STRING_LITERAL, txt.constData(), txt.size(), tk->lineno, false);
|
||||
}
|
||||
|
||||
if (newTk.hasSource()) {
|
||||
newTk.f.newline = tk->newline();
|
||||
newTk.f.whitespace = tk->whitespace();
|
||||
*tk = newTk;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Macro *macro = m_env->resolve(macroNameRef);
|
||||
Macro *macro = m_env->resolve(tk->asByteArrayRef());
|
||||
if (!macro
|
||||
|| (tk->expanded()
|
||||
&& m_state.m_tokenBuffer
|
||||
|
||||
@@ -334,7 +334,6 @@ private slots:
|
||||
void unfinished_function_like_macro_call();
|
||||
void nasty_macro_expansion();
|
||||
void glib_attribute();
|
||||
void builtin__FILE__();
|
||||
void blockSkipping();
|
||||
void includes_1();
|
||||
void dont_eagerly_expand();
|
||||
@@ -784,23 +783,6 @@ void tst_Preprocessor::glib_attribute()
|
||||
QCOMPARE(preprocessed, result____);
|
||||
}
|
||||
|
||||
void tst_Preprocessor::builtin__FILE__()
|
||||
{
|
||||
Client *client = 0; // no client.
|
||||
Environment env;
|
||||
|
||||
Preprocessor preprocess(client, &env);
|
||||
QByteArray preprocessed = preprocess.run(
|
||||
QLatin1String("some-file.c"),
|
||||
QByteArray("const char *f = __FILE__\n"
|
||||
));
|
||||
const QByteArray result____ =
|
||||
"# 1 \"some-file.c\"\n"
|
||||
"const char *f = \"some-file.c\"\n";
|
||||
|
||||
QCOMPARE(preprocessed, result____);
|
||||
}
|
||||
|
||||
void tst_Preprocessor::comparisons_data()
|
||||
{
|
||||
QTest::addColumn<QString>("infile");
|
||||
|
||||
Reference in New Issue
Block a user