summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/cppmodelmanager.cpp35
-rw-r--r--src/plugins/cpptools/rpp/pp-client.h9
-rw-r--r--src/plugins/cpptools/rpp/pp-engine.cpp34
3 files changed, 76 insertions, 2 deletions
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index 313ea7f21f..ccaff0bcfe 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -253,6 +253,25 @@ protected:
m_currentDoc->appendMacro(macroName, macroText);
}
+ virtual void startExpandingMacro(unsigned offset,
+ const rpp::Macro &macro,
+ const QByteArray &originalText)
+ {
+ if (! m_currentDoc)
+ return;
+
+ //qDebug() << "start expanding:" << macro.name << "text:" << originalText;
+ m_currentDoc->addMacroUse(offset, originalText.length());
+ }
+
+ virtual void stopExpandingMacro(unsigned offset, const rpp::Macro &macro)
+ {
+ if (! m_currentDoc)
+ return;
+
+ //qDebug() << "stop expanding:" << macro.name;
+ }
+
void mergeEnvironment(Document::Ptr doc)
{
QSet<QString> processed;
@@ -595,6 +614,22 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
QList<QTextEdit::ExtraSelection> selections;
+#ifdef QTCREATOR_WITH_MACRO_HIGHLIGHTING
+ // set up the format for the macros
+ QTextCharFormat macroFormat;
+ macroFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
+
+ QTextCursor c = ed->textCursor();
+ foreach (const Document::Block block, doc->macroUses()) {
+ QTextEdit::ExtraSelection sel;
+ sel.cursor = c;
+ sel.cursor.setPosition(block.begin());
+ sel.cursor.setPosition(block.end(), QTextCursor::KeepAnchor);
+ sel.format = macroFormat;
+ selections.append(sel);
+ }
+#endif // QTCREATOR_WITH_MACRO_HIGHLIGHTING
+
// set up the format for the errors
QTextCharFormat errorFormat;
errorFormat.setUnderlineStyle(QTextCharFormat::WaveUnderline);
diff --git a/src/plugins/cpptools/rpp/pp-client.h b/src/plugins/cpptools/rpp/pp-client.h
index 073fc44c36..974004a6ce 100644
--- a/src/plugins/cpptools/rpp/pp-client.h
+++ b/src/plugins/cpptools/rpp/pp-client.h
@@ -40,6 +40,8 @@
namespace rpp {
+class Macro;
+
class Client
{
Client(const Client &other);
@@ -61,6 +63,13 @@ public:
virtual void macroAdded(const QByteArray &macroId, const QByteArray &text) = 0;
virtual void sourceNeeded(QString &fileName, IncludeType mode) = 0; // ### FIX the signature.
+ virtual void startExpandingMacro(unsigned offset,
+ const Macro &macro,
+ const QByteArray &originalTextt) = 0;
+
+ virtual void stopExpandingMacro(unsigned offset,
+ const Macro &macro) = 0;
+
virtual void startSkippingBlocks(unsigned offset) = 0;
virtual void stopSkippingBlocks(unsigned offset) = 0;
};
diff --git a/src/plugins/cpptools/rpp/pp-engine.cpp b/src/plugins/cpptools/rpp/pp-engine.cpp
index 3a3e9245b3..2fa6e4ba67 100644
--- a/src/plugins/cpptools/rpp/pp-engine.cpp
+++ b/src/plugins/cpptools/rpp/pp-engine.cpp
@@ -575,7 +575,17 @@ void pp::operator()(const QByteArray &source, QByteArray *result)
const QByteArray spell = tokenSpell(*identifierToken);
if (env.isBuiltinMacro(spell)) {
+ const Macro trivial;
+
+ if (client)
+ client->startExpandingMacro(identifierToken->offset,
+ trivial, spell);
+
expand(spell.constBegin(), spell.constEnd(), result);
+
+ if (client)
+ client->stopExpandingMacro(_dot->offset, trivial);
+
continue;
}
@@ -585,10 +595,19 @@ void pp::operator()(const QByteArray &source, QByteArray *result)
} else {
if (! m->function_like) {
if (_dot->isNot(T_LPAREN)) {
+ if (client)
+ client->startExpandingMacro(identifierToken->offset,
+ *m, spell);
+
m->hidden = true;
+
expand(m->definition.constBegin(),
m->definition.constEnd(),
result);
+
+ if (client)
+ client->stopExpandingMacro(_dot->offset, *m);
+
m->hidden = false;
continue;
} else {
@@ -640,9 +659,20 @@ void pp::operator()(const QByteArray &source, QByteArray *result)
const char *beginOfText = startOfToken(*identifierToken);
const char *endOfText = endOfToken(*_dot);
++_dot; // skip T_RPAREN
- //m->hidden = true;
+
+ if (client) {
+ const QByteArray text =
+ QByteArray::fromRawData(beginOfText,
+ endOfText - beginOfText);
+
+ client->startExpandingMacro(identifierToken->offset,
+ *m, text);
+ }
+
expand(beginOfText, endOfText, result);
- //m->hidden = false;
+
+ if (client)
+ client->stopExpandingMacro(_dot->offset, *m);
}
}
}