Skip to content
Snippets Groups Projects
Commit fd62025d authored by Roberto Raggi's avatar Roberto Raggi
Browse files

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

Say hello to Snapshot::documentFromSource(), Snapshot::preprocessedCode() and Snapshot::globalNamespaceBinding().
parent d18b0195
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......@@ -45,6 +45,7 @@ namespace CPlusPlus {
class Macro;
class MacroArgumentReference;
class NamespaceBinding;
class CPLUSPLUS_EXPORT Document
{
......@@ -257,6 +258,8 @@ private:
QList<Block> _skippedBlocks;
QList<MacroUse> _macroUses;
QByteArray _source;
friend class Snapshot;
};
class CPLUSPLUS_EXPORT Snapshot: public QMap<QString, Document::Ptr>
......@@ -267,6 +270,14 @@ public:
Snapshot();
~Snapshot();
QByteArray preprocessedCode(const QByteArray &source,
const QString &fileName) const;
Document::Ptr documentFromSource(const QByteArray &preprocessedCode,
const QString &fileName) const;
QSharedPointer<NamespaceBinding> globalNamespaceBinding(Document::Ptr doc) const;
void insert(Document::Ptr doc);
using _Base::insert;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment