Say hello to Snapshot::documentFromSource(), Snapshot::preprocessedCode() and Snapshot::globalNamespaceBinding().

This commit is contained in:
Roberto Raggi
2009-06-03 16:16:20 +02:00
parent d18b0195e5
commit fd62025d63
2 changed files with 41 additions and 1 deletions

View File

@@ -28,7 +28,8 @@
**************************************************************************/
#include "CppDocument.h"
#include "pp.h"
#include "CppBindings.h"
#include "FastPreprocessor.h"
#include <Control.h>
#include <TranslationUnit.h>
@@ -345,3 +346,31 @@ void Snapshot::insert(Document::Ptr doc)
insert(doc->fileName(), doc);
}
QByteArray Snapshot::preprocessedCode(const QByteArray &source, const QString &fileName) const
{
FastPreprocessor pp(*this);
return pp.run(fileName, source);
}
Document::Ptr Snapshot::documentFromSource(const QByteArray &preprocessedCode,
const QString &fileName) const
{
if (Document::Ptr thisDocument = value(fileName)) {
FastPreprocessor pp(*this);
Document::Ptr newDoc = Document::create(fileName);
newDoc->_includes = thisDocument->_includes;
newDoc->_definedMacros = thisDocument->_definedMacros;
newDoc->setSource(preprocessedCode);
newDoc->parse();
return newDoc;
}
return Document::Ptr();
}
QSharedPointer<NamespaceBinding> Snapshot::globalNamespaceBinding(Document::Ptr doc) const
{
return CPlusPlus::bind(doc, *this);
}