aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorNikolai Kosjar <[email protected]>2013-11-29 11:25:47 +0100
committerNikolai Kosjar <[email protected]>2013-11-29 15:11:27 +0100
commit4c2daa90ce558c3b4287edc97127471486a411d9 (patch)
tree02250176caac60cb01e92cbefbe9166badf957c6 /src/libs
parent4edfe87b58ca8e5f92b6a10dcf98e3d240f38245 (diff)
C++: Fix highlighting for lines with predefined macros
This adds definitions for the macros __FILE__, __LINE__, __DATE__ and __TIME__ on demand. As a side effect, this also introduces highlighting for the uses of these macros. Task-number: QTCREATORBUG-8036 Change-Id: Ib7546c7d45d2eecbc50c7883fc684e3497154405 Reviewed-by: Erik Verbruggen <[email protected]> Reviewed-by: Eike Ziller <[email protected]> Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/cplusplus/Macro.h7
-rw-r--r--src/libs/cplusplus/pp-engine.cpp18
2 files changed, 17 insertions, 8 deletions
diff --git a/src/libs/cplusplus/Macro.h b/src/libs/cplusplus/Macro.h
index a3d83b1f00d..1c340dba650 100644
--- a/src/libs/cplusplus/Macro.h
+++ b/src/libs/cplusplus/Macro.h
@@ -137,6 +137,12 @@ public:
void setVariadic(bool isVariadic)
{ f._variadic = isVariadic; }
+ bool isPredefined() const
+ { return f._predefined; }
+
+ void setPredefined(bool isPredefined)
+ { f._predefined = isPredefined; }
+
QString toString() const;
QString toStringWithLineBreaks() const;
@@ -151,6 +157,7 @@ private:
unsigned _hidden: 1;
unsigned _functionLike: 1;
unsigned _variadic: 1;
+ unsigned _predefined: 1;
};
QByteArray _name;
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index 05a7a083d38..4bbb229734b 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -917,23 +917,21 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
&& macroNameRef[0] == '_'
&& macroNameRef[1] == '_') {
PPToken newTk;
+ QByteArray txt;
if (macroNameRef == ppLine) {
- QByteArray txt = QByteArray::number(tk->lineno);
+ 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('"');
@@ -941,10 +939,14 @@ bool Preprocessor::handleIdentifier(PPToken *tk)
}
if (newTk.hasSource()) {
- newTk.f.newline = tk->newline();
- newTk.f.whitespace = tk->whitespace();
- *tk = newTk;
- return false;
+ Macro macro;
+ macro.setName(macroNameRef.toByteArray());
+ macro.setFileName(m_env->currentFile);
+ macro.setPredefined(true);
+ macro.setDefinition(txt, QVector<PPToken>() << newTk);
+ m_env->bind(macro);
+ if (m_client)
+ m_client->macroAdded(macro);
}
}