Commit dbeae8cb authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

C++: FastPreprocessor: Add only includes if there are none



For the case that the document is based upon another one (see
Snapshot::preprocessedDocument(), the only client of FastPreprocessor)
the FastPreprocessor added extra unresolved includes.

Change-Id: I0a7719fa8806af59f87a48bc6914270efd653e84
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 8f988a0a
......@@ -40,11 +40,14 @@ using namespace CPlusPlus;
FastPreprocessor::FastPreprocessor(const Snapshot &snapshot)
: _snapshot(snapshot)
, _preproc(this, &_env)
, _addIncludesToCurrentDoc(false)
{ }
QByteArray FastPreprocessor::run(Document::Ptr newDoc, const QByteArray &source)
{
std::swap(newDoc, _currentDoc);
_addIncludesToCurrentDoc = _currentDoc->resolvedIncludes().isEmpty()
&& _currentDoc->unresolvedIncludes().isEmpty();
const QString fileName = _currentDoc->fileName();
_preproc.setExpandFunctionlikeMacros(false);
_preproc.setKeepComments(true);
......@@ -72,9 +75,11 @@ void FastPreprocessor::sourceNeeded(unsigned line, const QString &fileName, Incl
{
Q_UNUSED(initialIncludes)
Q_ASSERT(_currentDoc);
// CHECKME: Is that cleanName needed?
QString cleanName = QDir::cleanPath(fileName);
_currentDoc->addIncludeFile(Document::Include(fileName, cleanName, line, mode));
if (_addIncludesToCurrentDoc) {
// CHECKME: Is that cleanName needed?
const QString cleanName = QDir::cleanPath(fileName);
_currentDoc->addIncludeFile(Document::Include(fileName, cleanName, line, mode));
}
mergeEnvironment(fileName);
}
......
......@@ -49,6 +49,7 @@ class CPLUSPLUS_EXPORT FastPreprocessor: public Client
Preprocessor _preproc;
QSet<QString> _merged;
Document::Ptr _currentDoc;
bool _addIncludesToCurrentDoc;
void mergeEnvironment(const QString &fileName);
......
......@@ -143,13 +143,6 @@ LineForNewIncludeDirective::LineForNewIncludeDirective(const QTextDocument *text
m_includes = includes;
}
// TODO: Remove this filter loop once FastPreprocessor::sourceNeeded does not add
// extra includes anymore.
for (int i = m_includes.count() - 1; i >= 0; --i) {
if (!QFileInfo(m_includes.at(i).resolvedFileName()).isAbsolute())
m_includes.removeAt(i);
}
// Detect include style
if (m_includeStyle == AutoDetect) {
unsigned timesIncludeStyleChanged = 0;
......
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