forked from qt-creator/qt-creator
Introduced processNewline() and processSkippingBlocks().
This commit is contained in:
@@ -526,6 +526,51 @@ Preprocessor::State Preprocessor::createStateFromSource(const QByteArray &source
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Preprocessor::processNewline()
|
||||||
|
{
|
||||||
|
if (env.currentLine == _dot->lineno)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (env.currentLine > _dot->lineno) {
|
||||||
|
_result->append("\n# ");
|
||||||
|
_result->append(QByteArray::number(_dot->lineno));
|
||||||
|
_result->append(' ');
|
||||||
|
_result->append('"');
|
||||||
|
_result->append(env.currentFile);
|
||||||
|
_result->append('"');
|
||||||
|
_result->append('\n');
|
||||||
|
} else {
|
||||||
|
for (unsigned i = env.currentLine; i < _dot->lineno; ++i)
|
||||||
|
_result->append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
env.currentLine = _dot->lineno;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Preprocessor::processSkippingBlocks(bool skippingBlocks,
|
||||||
|
TokenIterator start, TokenIterator /*end*/)
|
||||||
|
{
|
||||||
|
if (! client)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (skippingBlocks != _skipping[iflevel]) {
|
||||||
|
unsigned offset = start->offset;
|
||||||
|
|
||||||
|
if (_skipping[iflevel]) {
|
||||||
|
if (_dot->newline)
|
||||||
|
++offset;
|
||||||
|
|
||||||
|
client->startSkippingBlocks(offset);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (offset)
|
||||||
|
--offset;
|
||||||
|
|
||||||
|
client->stopSkippingBlocks(offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Preprocessor::preprocess(const QByteArray &fileName, const QByteArray &source,
|
void Preprocessor::preprocess(const QByteArray &fileName, const QByteArray &source,
|
||||||
QByteArray *result)
|
QByteArray *result)
|
||||||
{
|
{
|
||||||
@@ -541,62 +586,43 @@ void Preprocessor::preprocess(const QByteArray &fileName, const QByteArray &sour
|
|||||||
env.currentLine = 0;
|
env.currentLine = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (env.currentLine != _dot->lineno) {
|
processNewline();
|
||||||
if (env.currentLine > _dot->lineno) {
|
|
||||||
_result->append("\n# ");
|
|
||||||
_result->append(QByteArray::number(_dot->lineno));
|
|
||||||
_result->append(' ');
|
|
||||||
_result->append('"');
|
|
||||||
_result->append(env.currentFile);
|
|
||||||
_result->append('"');
|
|
||||||
_result->append('\n');
|
|
||||||
} else {
|
|
||||||
for (unsigned i = env.currentLine; i < _dot->lineno; ++i)
|
|
||||||
_result->append('\n');
|
|
||||||
}
|
|
||||||
env.currentLine = _dot->lineno;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_dot->is(T_EOF_SYMBOL)) {
|
if (_dot->is(T_EOF_SYMBOL)) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else if (_dot->is(T_POUND) && (! _dot->joined && _dot->newline)) {
|
} else if (_dot->is(T_POUND) && (! _dot->joined && _dot->newline)) {
|
||||||
|
// handle the preprocessor directive
|
||||||
|
|
||||||
TokenIterator start = _dot;
|
TokenIterator start = _dot;
|
||||||
do {
|
do {
|
||||||
++_dot;
|
++_dot;
|
||||||
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
|
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
|
||||||
|
|
||||||
//qDebug() << QByteArray(first + beginPP.offset,
|
|
||||||
//tokens.last().end() - beginPP.offset);
|
|
||||||
|
|
||||||
const bool skippingBlocks = _skipping[iflevel];
|
const bool skippingBlocks = _skipping[iflevel];
|
||||||
|
|
||||||
processDirective(start, _dot);
|
processDirective(start, _dot);
|
||||||
|
processSkippingBlocks(skippingBlocks, start, _dot);
|
||||||
|
|
||||||
if (client && skippingBlocks != _skipping[iflevel]) {
|
|
||||||
unsigned offset = start->offset;
|
|
||||||
if (_skipping[iflevel]) {
|
|
||||||
if (_dot->newline)
|
|
||||||
++offset;
|
|
||||||
client->startSkippingBlocks(offset);
|
|
||||||
} else {
|
|
||||||
if (offset)
|
|
||||||
--offset;
|
|
||||||
client->stopSkippingBlocks(offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (skipping()) {
|
} else if (skipping()) {
|
||||||
|
// skip the current line
|
||||||
|
|
||||||
do {
|
do {
|
||||||
++_dot;
|
++_dot;
|
||||||
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
|
} while (_dot->isNot(T_EOF_SYMBOL) && (_dot->joined || ! _dot->newline));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (_dot->joined)
|
if (_dot->joined)
|
||||||
_result->append("\\\n");
|
_result->append("\\\n");
|
||||||
|
|
||||||
else if (_dot->whitespace)
|
else if (_dot->whitespace)
|
||||||
_result->append(' ');
|
_result->append(' ');
|
||||||
|
|
||||||
if (_dot->isNot(T_IDENTIFIER)) {
|
if (_dot->isNot(T_IDENTIFIER)) {
|
||||||
_result->append(tokenSpell(*_dot));
|
_result->append(tokenSpell(*_dot));
|
||||||
++_dot;
|
++_dot;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const TokenIterator identifierToken = _dot;
|
const TokenIterator identifierToken = _dot;
|
||||||
++_dot; // skip T_IDENTIFIER
|
++_dot; // skip T_IDENTIFIER
|
||||||
|
|||||||
@@ -191,6 +191,10 @@ private:
|
|||||||
QByteArray tokenSpell(const CPlusPlus::Token &token) const;
|
QByteArray tokenSpell(const CPlusPlus::Token &token) const;
|
||||||
QByteArray tokenText(const CPlusPlus::Token &token) const; // does a deep copy
|
QByteArray tokenText(const CPlusPlus::Token &token) const; // does a deep copy
|
||||||
|
|
||||||
|
void processNewline();
|
||||||
|
void processSkippingBlocks(bool skippingBlocks,
|
||||||
|
TokenIterator dot, TokenIterator lastToken);
|
||||||
|
|
||||||
void processDirective(TokenIterator dot, TokenIterator lastToken);
|
void processDirective(TokenIterator dot, TokenIterator lastToken);
|
||||||
void processInclude(bool skipCurrentPath,
|
void processInclude(bool skipCurrentPath,
|
||||||
TokenIterator dot, TokenIterator lastToken,
|
TokenIterator dot, TokenIterator lastToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user