Merge branch 'master' of git@scm.dev.nokia.troll.no:creator/mainline

This commit is contained in:
Friedemann Kleint
2009-02-23 14:46:56 +01:00
3 changed files with 105 additions and 36 deletions

View File

@@ -117,6 +117,13 @@ Macro *Environment::bind(const Macro &__macro)
return m; return m;
} }
void Environment::addMacros(const QList<Macro> &macros)
{
foreach (const Macro &macro, macros) {
bind(macro);
}
}
Macro *Environment::remove(const QByteArray &name) Macro *Environment::remove(const QByteArray &name)
{ {
Macro macro; Macro macro;
@@ -127,6 +134,23 @@ Macro *Environment::remove(const QByteArray &name)
return bind(macro); return bind(macro);
} }
void Environment::reset()
{
if (_macros) {
qDeleteAll(firstMacro(), lastMacro());
free(_macros);
}
if (_hash)
free(_hash);
_macros = 0;
_allocated_macros = 0;
_macro_count = -1;
_hash = 0;
_hash_count = 401;
}
bool Environment::isBuiltinMacro(const QByteArray &s) const bool Environment::isBuiltinMacro(const QByteArray &s) const
{ {
if (s.length() != 8) if (s.length() != 8)

View File

@@ -56,6 +56,7 @@
#include "CPlusPlusForwardDeclarations.h" #include "CPlusPlusForwardDeclarations.h"
#include <QVector> #include <QVector>
#include <QList>
#include <QByteArray> #include <QByteArray>
namespace CPlusPlus { namespace CPlusPlus {
@@ -89,6 +90,9 @@ public:
Macro **lastMacro() Macro **lastMacro()
{ return _macros + _macro_count + 1; } { return _macros + _macro_count + 1; }
void reset();
void addMacros(const QList<Macro> &macros);
private: private:
static unsigned hashCode(const QByteArray &s); static unsigned hashCode(const QByteArray &s);
void rehash(); void rehash();

View File

@@ -48,6 +48,7 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h> #include <coreplugin/uniqueidmanager.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -171,6 +172,8 @@ public:
void run(QString &fileName); void run(QString &fileName);
void operator()(QString &fileName); void operator()(QString &fileName);
void resetEnvironment();
public: // attributes public: // attributes
Snapshot snapshot; Snapshot snapshot;
@@ -230,6 +233,9 @@ void CppPreprocessor::setProjectFiles(const QStringList &files)
void CppPreprocessor::run(QString &fileName) void CppPreprocessor::run(QString &fileName)
{ sourceNeeded(fileName, IncludeGlobal, /*line = */ 0); } { sourceNeeded(fileName, IncludeGlobal, /*line = */ 0); }
void CppPreprocessor::resetEnvironment()
{ env.reset(); }
void CppPreprocessor::operator()(QString &fileName) void CppPreprocessor::operator()(QString &fileName)
{ run(fileName); } { run(fileName); }
@@ -390,7 +396,7 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet<QString> *process
processed->insert(fn); processed->insert(fn);
foreach (Document::Include incl, doc->includes()) { foreach (const Document::Include &incl, doc->includes()) {
QString includedFile = incl.fileName(); QString includedFile = incl.fileName();
if (Document::Ptr includedDoc = snapshot.value(includedFile)) if (Document::Ptr includedDoc = snapshot.value(includedFile))
@@ -399,9 +405,7 @@ void CppPreprocessor::mergeEnvironment(Document::Ptr doc, QSet<QString> *process
run(includedFile); run(includedFile);
} }
foreach (const Macro macro, doc->definedMacros()) { env.addMacros(doc->definedMacros());
env.bind(macro);
}
} }
void CppPreprocessor::startSkippingBlocks(unsigned offset) void CppPreprocessor::startSkippingBlocks(unsigned offset)
@@ -428,56 +432,58 @@ void CppPreprocessor::sourceNeeded(QString &fileName, IncludeType type,
if (m_currentDoc) { if (m_currentDoc) {
m_currentDoc->addIncludeFile(fileName, line); m_currentDoc->addIncludeFile(fileName, line);
if (contents.isEmpty() && ! QFileInfo(fileName).isAbsolute()) { if (contents.isEmpty() && ! QFileInfo(fileName).isAbsolute()) {
QString msg; QString msg;
msg += fileName; msg += fileName;
msg += QLatin1String(": No such file or directory"); msg += QLatin1String(": No such file or directory");
Document::DiagnosticMessage d(Document::DiagnosticMessage::Warning, Document::DiagnosticMessage d(Document::DiagnosticMessage::Warning,
m_currentDoc->fileName(), m_currentDoc->fileName(),
env.currentLine, /*column = */ 0, env.currentLine, /*column = */ 0,
msg); msg);
m_currentDoc->addDiagnosticMessage(d); m_currentDoc->addDiagnosticMessage(d);
//qWarning() << "file not found:" << fileName << m_currentDoc->fileName() << env.current_line; //qWarning() << "file not found:" << fileName << m_currentDoc->fileName() << env.current_line;
} }
} }
if (! contents.isEmpty()) { //qDebug() << "parse file:" << fileName << "contents:" << contents.size();
Document::Ptr cachedDoc = snapshot.value(fileName);
if (cachedDoc && m_currentDoc) {
mergeEnvironment(cachedDoc);
} else {
Document::Ptr previousDoc = switchDocument(Document::create(fileName));
const QByteArray previousFile = env.currentFile; Document::Ptr doc = snapshot.value(fileName);
const unsigned previousLine = env.currentLine; if (doc) {
mergeEnvironment(doc);
return;
}
TranslationUnit *unit = m_currentDoc->translationUnit(); doc = Document::create(fileName);
env.currentFile = QByteArray(unit->fileName(), unit->fileNameLength());
Document::Ptr previousDoc = switchDocument(doc);
QByteArray preprocessedCode; QByteArray preprocessedCode;
m_proc(contents, &preprocessedCode); m_proc(fileName.toUtf8(), contents, &preprocessedCode);
//qDebug() << preprocessedCode;
env.currentFile = previousFile; doc->setSource(preprocessedCode);
env.currentLine = previousLine;
m_currentDoc->setSource(preprocessedCode); doc->parse();
m_currentDoc->parse(); doc->check();
#if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU) #if defined(QTCREATOR_WITH_DUMP_AST) && defined(Q_CC_GNU)
DumpAST dump(m_currentDoc->control()); DumpAST dump(m_currentDoc->control());
dump(m_currentDoc->translationUnit()->ast()); dump(m_currentDoc->translationUnit()->ast());
#endif #endif
m_currentDoc->check(); doc->releaseTranslationUnit();
m_currentDoc->releaseTranslationUnit(); // release the AST and the token stream.
snapshot[fileName] = doc;
if (m_modelManager) if (m_modelManager)
m_modelManager->emitDocumentUpdated(m_currentDoc); m_modelManager->emitDocumentUpdated(m_currentDoc); // ### TODO: compress
(void) switchDocument(previousDoc); (void) switchDocument(previousDoc);
} }
}
}
Document::Ptr CppPreprocessor::switchDocument(Document::Ptr doc) Document::Ptr CppPreprocessor::switchDocument(Document::Ptr doc)
{ {
@@ -741,7 +747,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
QList<TextEditor::BaseTextEditor::BlockRange> blockRanges; QList<TextEditor::BaseTextEditor::BlockRange> blockRanges;
foreach (const Document::Block block, doc->skippedBlocks()) { foreach (const Document::Block &block, doc->skippedBlocks()) {
blockRanges.append(TextEditor::BaseTextEditor::BlockRange(block.begin(), block.end())); blockRanges.append(TextEditor::BaseTextEditor::BlockRange(block.begin(), block.end()));
} }
ed->setIfdefedOutBlocks(blockRanges); ed->setIfdefedOutBlocks(blockRanges);
@@ -754,7 +760,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
macroFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline); macroFormat.setUnderlineStyle(QTextCharFormat::SingleUnderline);
QTextCursor c = ed->textCursor(); QTextCursor c = ed->textCursor();
foreach (const Document::Block block, doc->macroUses()) { foreach (const Document::MacroUse &block, doc->macroUses()) {
QTextEdit::ExtraSelection sel; QTextEdit::ExtraSelection sel;
sel.cursor = c; sel.cursor = c;
sel.cursor.setPosition(block.begin()); sel.cursor.setPosition(block.begin());
@@ -775,7 +781,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
warningFormat.setUnderlineColor(Qt::darkYellow); warningFormat.setUnderlineColor(Qt::darkYellow);
QSet<int> lines; QSet<int> lines;
foreach (const Document::DiagnosticMessage m, doc->diagnosticMessages()) { foreach (const Document::DiagnosticMessage &m, doc->diagnosticMessages()) {
if (m.fileName() != fileName) if (m.fileName() != fileName)
continue; continue;
else if (lines.contains(m.line())) else if (lines.contains(m.line()))
@@ -803,7 +809,7 @@ void CppModelManager::onDocumentUpdated(Document::Ptr doc)
} }
QList<Editor> todo; QList<Editor> todo;
foreach (Editor e, todo) { foreach (const Editor &e, todo) {
if (e.widget != ed) if (e.widget != ed)
todo.append(e); todo.append(e);
} }
@@ -826,7 +832,7 @@ void CppModelManager::postEditorUpdate()
void CppModelManager::updateEditorSelections() void CppModelManager::updateEditorSelections()
{ {
foreach (Editor ed, m_todo) { foreach (const Editor &ed, m_todo) {
if (! ed.widget) if (! ed.widget)
continue; continue;
@@ -876,20 +882,38 @@ void CppModelManager::parse(QFutureInterface<void> &future,
if (files.isEmpty()) if (files.isEmpty())
return; return;
foreach (QString file, files) { Core::MimeDatabase *db = Core::ICore::instance()->mimeDatabase();
QStringList headers, sources;
Core::MimeType cSourceTy = db->findByType(QLatin1String("text/x-csrc"));
Core::MimeType cppSourceTy = db->findByType(QLatin1String("text/x-c++src"));
foreach (const QString &file, files) {
const QFileInfo fileInfo(file);
if (cSourceTy.matchesFile(fileInfo) || cppSourceTy.matchesFile(fileInfo))
sources.append(file);
else
headers.append(file);
}
foreach (const QString &file, files) {
preproc->snapshot.remove(file); preproc->snapshot.remove(file);
} }
files = sources;
files += headers;
// Change the priority of the background parser thread to idle. // Change the priority of the background parser thread to idle.
QThread::currentThread()->setPriority(QThread::IdlePriority); QThread::currentThread()->setPriority(QThread::IdlePriority);
future.setProgressRange(0, files.size()); future.setProgressRange(0, files.size());
QString conf = QLatin1String(pp_configuration_file); QString conf = QLatin1String(pp_configuration_file);
(void) preproc->run(conf);
const int STEP = 10; const int STEP = 10;
bool processingHeaders = false;
for (int i = 0; i < files.size(); ++i) { for (int i = 0; i < files.size(); ++i) {
if (future.isPaused()) if (future.isPaused())
future.waitForResume(); future.waitForResume();
@@ -905,8 +929,25 @@ void CppModelManager::parse(QFutureInterface<void> &future,
#endif #endif
QString fileName = files.at(i); QString fileName = files.at(i);
bool isSourceFile = false;
if (cppSourceTy.matchesFile(fileName) || cSourceTy.matchesFile(fileName))
isSourceFile = true;
if (isSourceFile)
(void) preproc->run(conf);
else if (! processingHeaders) {
(void) preproc->run(conf);
processingHeaders = true;
}
preproc->run(fileName); preproc->run(fileName);
if (isSourceFile)
preproc->resetEnvironment();
if (! (i % STEP)) // Yields execution of the current thread. if (! (i % STEP)) // Yields execution of the current thread.
QThread::yieldCurrentThread(); QThread::yieldCurrentThread();