[Uml-devel] KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser

Ralf Habacker ralf.habacker at gmail.com
Sat Jul 7 15:43:20 UTC 2012


SVN commit 1304519 by habacker:

Added dumpToFile() to PreprocessLexer, which dumps preprocessed files into
<tempdir>/umbrello-<pid> to be able to find preprocess errors.

 M  +28 -1     preprocesslexer.cpp  
 M  +1 -0      preprocesslexer.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp #1304518:1304519
@@ -28,6 +28,9 @@
 #include <QtCore/QRegExp>
 #include <QtCore/QMap>
 #include <QtCore/QList>
+#include <QtCore/QFile>
+#include <QtCore/QDir>
+#include <QtCore/QCoreApplication>
 
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
@@ -36,6 +39,8 @@
 
 #include "assignFunctor.hpp"
 
+#define PREPROCESSLEXER_DEBUG
+
 #ifdef Q_CC_MSVC
 template <class _Tp>
 struct _Identity : public std::unary_function<_Tp,_Tp> {
@@ -578,13 +583,35 @@
         m_preprocessedString += *p_first;
 }
 
+/**
+ * dump preprocess file to temporay location
+ */
+void PreprocessLexer::dumpToFile()
+{
+    QString tempPath = QDir::tempPath() + QString("/umbrello-%1").arg(QCoreApplication::applicationPid());
+    QDir d(tempPath);
+    if (!d.exists())
+        d.mkdir(tempPath);
+
+    QString fileName = tempPath + '/' + currentPosition().file.toString().replace('/','-');
+    fileName = fileName.replace("/-","/");
+    QFile f(fileName);
+    if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
+        QTextStream out(&f);
+        out << m_preprocessedString;
+    }
+}
+
 bool PreprocessLexer::preprocess()
 {
     for (;;) {
         Position start = currentPosition();
         nextLine();
         if (currentPosition() == start) {
-            uError() << "failed to preprocess file" << start;
+#ifdef PREPROCESSLEXER_DEBUG
+            dumpToFile();
+#endif
+            uError() << "preprocess failed" << start;
             return false;
         }
 
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.h #1304518:1304519
@@ -206,6 +206,7 @@
     QString const& preprocessedString() const {return m_preprocessedString;}
 private:
     static int toInt( const Token& token );
+    void dumpToFile();
 
     void addDependence( std::pair<QString, int> const& p_wordAndScope) const {
         m_driver->addDependence(m_driver->currentFileName(),




More information about the umbrello-devel mailing list