Commit 4edfe87b authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

Revert "Preprocessor Enginge: fix bug in pp-engine.cpp"

Breaks highlighting for macros using the predefined macros.

This reverts commit 1d834c11

.

Change-Id: Ic13c407e293a806a63ff30153864530df6a32e47
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent b2ff8d87
...@@ -906,7 +906,49 @@ bool Preprocessor::handleIdentifier(PPToken *tk) ...@@ -906,7 +906,49 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
{ {
ScopedBoolSwap s(m_state.m_inPreprocessorDirective, true); ScopedBoolSwap s(m_state.m_inPreprocessorDirective, true);
Macro *macro = m_env->resolve(tk->asByteArrayRef()); 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);
if (!macro if (!macro
|| (tk->expanded() || (tk->expanded()
&& m_state.m_tokenBuffer && m_state.m_tokenBuffer
......
...@@ -334,6 +334,7 @@ private slots: ...@@ -334,6 +334,7 @@ private slots:
void unfinished_function_like_macro_call(); void unfinished_function_like_macro_call();
void nasty_macro_expansion(); void nasty_macro_expansion();
void glib_attribute(); void glib_attribute();
void builtin__FILE__();
void blockSkipping(); void blockSkipping();
void includes_1(); void includes_1();
void dont_eagerly_expand(); void dont_eagerly_expand();
...@@ -783,6 +784,23 @@ void tst_Preprocessor::glib_attribute() ...@@ -783,6 +784,23 @@ void tst_Preprocessor::glib_attribute()
QCOMPARE(preprocessed, result____); 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() void tst_Preprocessor::comparisons_data()
{ {
QTest::addColumn<QString>("infile"); QTest::addColumn<QString>("infile");
......
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