diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index ba8d1508182e349646d009c5b968fa069c40d383..786f07a79bf665638cf74e8e16a8f1cfa91355f6 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -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); +} diff --git a/src/libs/cplusplus/CppDocument.h b/src/libs/cplusplus/CppDocument.h index 01da6b62d219c9d7e07e1b0acfe728de0e870eba..e5ead401417d586d6d97efadab11da45de75d66d 100644 --- a/src/libs/cplusplus/CppDocument.h +++ b/src/libs/cplusplus/CppDocument.h @@ -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;