[C++] Rewrite of the preprocessor.

This rewrite fixes a couple of issues with the pre-processor. It now
supports:
- macros in macro bodies
- stringification of parameters [cpp.stringize]
- the concatenation operator [cpp.concat]
- #include MACRO_HERE
- defined() inside macro bodies used in pp-conditions.

Change-Id: Ifdb78041fb6afadf44f939a4bd66ce2832b8601f
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
Erik Verbruggen
2012-03-26 15:18:01 +02:00
parent 159058d9eb
commit 60db573660
50 changed files with 1843 additions and 1620 deletions

View File

@@ -79,7 +79,7 @@
using namespace CPlusPlus;
using namespace CppEditor;
using namespace CppTools;
using namespace Internal;
using namespace CppTools::Internal;
using namespace TextEditor;
namespace CppTools {

View File

@@ -503,7 +503,7 @@ void CppPreprocessor::passedMacroDefinitionCheck(unsigned offset, const Macro &m
return;
m_currentDoc->addMacroUse(macro, offset, macro.name().length(), env.currentLine,
QVector<MacroArgumentReference>(), true);
QVector<MacroArgumentReference>());
}
void CppPreprocessor::failedMacroDefinitionCheck(unsigned offset, const QByteArray &name)
@@ -517,7 +517,6 @@ void CppPreprocessor::failedMacroDefinitionCheck(unsigned offset, const QByteArr
void CppPreprocessor::startExpandingMacro(unsigned offset,
const Macro &macro,
const QByteArray &originalText,
bool inCondition,
const QVector<MacroArgumentReference> &actuals)
{
if (! m_currentDoc)
@@ -525,7 +524,7 @@ void CppPreprocessor::startExpandingMacro(unsigned offset,
//qDebug() << "start expanding:" << macro.name() << "text:" << originalText;
m_currentDoc->addMacroUse(macro, offset, originalText.length(), env.currentLine,
actuals, inCondition);
actuals);
}
void CppPreprocessor::stopExpandingMacro(unsigned, const Macro &)
@@ -600,7 +599,9 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type, unsigned
}
}
//qDebug() << "parse file:" << fileName << "contents:" << contents.size();
// qDebug() << "parse file:" << fileName
// << "contents:" << contents.size()
// ;
Document::Ptr doc = snapshot.document(fileName);
if (doc) {
@@ -620,6 +621,8 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type, unsigned
const QByteArray preprocessedCode = preprocess(fileName, contents);
// { QByteArray b(preprocessedCode); b.replace("\n", "<<<\n"); qDebug("Preprocessed code for \"%s\": [[%s]]", fileName.toUtf8().constData(), b.constData()); }
doc->setUtf8Source(preprocessedCode);
doc->keepSourceAndAST();
doc->tokenize();

View File

@@ -303,7 +303,6 @@ protected:
virtual void startExpandingMacro(unsigned offset,
const CPlusPlus::Macro &macro,
const QByteArray &originalText,
bool inCondition,
const QVector<CPlusPlus::MacroArgumentReference> &actuals);
virtual void stopExpandingMacro(unsigned offset, const CPlusPlus::Macro &macro);
virtual void startSkippingBlocks(unsigned offset);