From fd62025d633318d4ae1b76827d50def1e50c98ed Mon Sep 17 00:00:00 2001
From: Roberto Raggi <roberto.raggi@nokia.com>
Date: Wed, 3 Jun 2009 16:16:20 +0200
Subject: [PATCH] Say hello to Snapshot::documentFromSource(),
 Snapshot::preprocessedCode() and Snapshot::globalNamespaceBinding().

---
 src/libs/cplusplus/CppDocument.cpp | 31 +++++++++++++++++++++++++++++-
 src/libs/cplusplus/CppDocument.h   | 11 +++++++++++
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp
index ba8d1508182..786f07a79bf 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 01da6b62d21..e5ead401417 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;
-- 
GitLab