[umbrello-devel] [PATCH 2/3] kdevcppparser: Replace PositionFilename with a typedef to QString.

Raphael Kubo da Costa rakuco at FreeBSD.org
Sun Nov 3 13:12:19 UTC 2013


The C++ standard (98, 03 and 11) states that std::basic_string is supposed
to work only with POD-like types, which is not the case for QChar.

GCC's libstdc++'s std::basic_string implementation, though, does not use any
features present only in POD types, so the previous behavior of using
std::basic_string<QChar> has worked for most people using Linux, and some
workarounds were present for other compilers such as SunPro CC and MSVC.

Instead of adding yet another workaround to get things working with clang
with libc++, try to fix the problem in a different way by getting rid of the
need for std::basic_string in position.h altogether and using a plain
QString instead.

std::basic_string was used only to store the name of the source file being
processed, which was originally a QString anyway, so we can avoid the
QString -> std::basic_string -> QString conversions, as well as the need to
have a full-fledged PositionFilename class with a toString() method that
performed this conversion.

It also allows us to remove the MSVC/SunPro workarounds from the code and
the build system.
---
 umbrello/CMakeLists.txt                            | 46 +++++++---------------
 umbrello/codeimport/classimport.cpp                |  7 ----
 umbrello/codeimport/kdevcppparser/position.h       | 45 +--------------------
 .../codeimport/kdevcppparser/preprocesslexer.cpp   |  2 +-
 4 files changed, 17 insertions(+), 83 deletions(-)

diff --git a/umbrello/CMakeLists.txt b/umbrello/CMakeLists.txt
index 1f7e47e..ce37b6e 100644
--- a/umbrello/CMakeLists.txt
+++ b/umbrello/CMakeLists.txt
@@ -267,37 +267,21 @@ set(libcodeimport_SRCS
     codeimport/csharp/csharpimport.cpp
 )
 
-if (WIN32 AND NOT MSVC)
-    # SunPRO CC have a problem with position.h; we try to put a
-    # QChar into a spirit iterator, which, after a bunch of futzing, ends up in
-    # the STL string_ref templates, which use
-    #
-    #     union {
-    #        size_type _C_size;    // Number of actual data values stored
-    #        _CharT    _C_dummy;   // force the alignment of the first char
-    #     } _C_size;               // named to work around an HP aCC 3.30 bug
-    #
-    # and you can't have a class which requires an initializer in a union.
-    #
-    add_definitions(-DDISABLE_CPP_IMPORT)
-    set(libkdevcppparser_SRCS)
-else (WIN32 AND NOT MSVC)
-    list(APPEND libcodeimport_SRCS
-        codeimport/cppimport.cpp
-    )
-    set(libkdevcppparser_SRCS
-        codeimport/kdevcppparser/ast.cpp
-        codeimport/kdevcppparser/driver.cpp
-        codeimport/kdevcppparser/errors.cpp
-        codeimport/kdevcppparser/lexer.cpp
-        codeimport/kdevcppparser/lookup.cpp
-        codeimport/kdevcppparser/parser.cpp
-        codeimport/kdevcppparser/preprocesslexer.cpp
-        codeimport/kdevcppparser/tree_parser.cpp
-        codeimport/kdevcppparser/ast_utils.cpp
-        codeimport/kdevcppparser/cpptree2uml.cpp
-    )
-endif(WIN32 AND NOT MSVC)
+list(APPEND libcodeimport_SRCS
+    codeimport/cppimport.cpp
+)
+set(libkdevcppparser_SRCS
+    codeimport/kdevcppparser/ast.cpp
+    codeimport/kdevcppparser/driver.cpp
+    codeimport/kdevcppparser/errors.cpp
+    codeimport/kdevcppparser/lexer.cpp
+    codeimport/kdevcppparser/lookup.cpp
+    codeimport/kdevcppparser/parser.cpp
+    codeimport/kdevcppparser/preprocesslexer.cpp
+    codeimport/kdevcppparser/tree_parser.cpp
+    codeimport/kdevcppparser/ast_utils.cpp
+    codeimport/kdevcppparser/cpptree2uml.cpp
+)
 
 set(libclipboard_SRCS
     clipboard/umldragdata.cpp
diff --git a/umbrello/codeimport/classimport.cpp b/umbrello/codeimport/classimport.cpp
index 028244f..6b4dde0 100644
--- a/umbrello/codeimport/classimport.cpp
+++ b/umbrello/codeimport/classimport.cpp
@@ -20,9 +20,7 @@
 #include "javaimport.h"
 #include "adaimport.h"
 #include "pascalimport.h"
-#ifndef DISABLE_CPP_IMPORT
 #include "cppimport.h"
-#endif
 #include "csharpimport.h"
 #include "codeimpthread.h"
 
@@ -52,13 +50,8 @@ ClassImport *ClassImport::createImporterByFileExt(const QString &fileName, CodeI
         classImporter = new PascalImport(thread);
     else if (fileName.endsWith(QLatin1String(".cs")))
         classImporter = new CSharpImport(thread);
-#ifndef DISABLE_CPP_IMPORT
     else
         classImporter = new CppImport(thread);  // the default.
-#else
-    else 
-        classImporter = 0;
-#endif
     return classImporter;
 }
 
diff --git a/umbrello/codeimport/kdevcppparser/position.h b/umbrello/codeimport/kdevcppparser/position.h
index 58db2d4..32c911c 100644
--- a/umbrello/codeimport/kdevcppparser/position.h
+++ b/umbrello/codeimport/kdevcppparser/position.h
@@ -20,22 +20,6 @@
 #ifndef POSITION_H
 #define POSITION_H
 
-#ifdef _MSC_VER //Q_CC_MSVC isn't defined here
-/*
-workaround for the following msvc error 
-...\Microsoft Visual Studio 8\VC\INCLUDE\xstring(2044) : error C2620: 
-    member 'std::basic_string<_Elem>::_Bxty::_Buf ' of union 'std::basic_string<_Elem>::_Bxty' 
-    has user-defined constructor or non-trivial default constructor with [  _Elem=QChar]
-...\Microsoft Visual Studio 8\VC\INCLUDE\xstring(2046) : see reference to class 
-    template instantiation 'std::basic_string<_Elem>::_Bxty' being compiled with [  _Elem=QChar]
-..\umbrello\umbrello\codeimport\kdevcppparser\position.h(49) : see reference to class 
-    template instantiation 'std::basic_string<_Elem>' being compiled with [  _Elem=QChar]
-*/
-#define union struct 
-#include <xstring>
-#undef union 
-#endif
-
 #include <limits.h>
 #include <boost/version.hpp>
 #include <boost/spirit/include/classic.hpp>
@@ -43,34 +27,7 @@ workaround for the following msvc error
 #include <QChar>
 #include <QDebug>
 
-typedef std::basic_string<QChar> PositionFilenameType;
-
-class PositionFilename : public PositionFilenameType
-{
-public:
-    PositionFilename()
-    {
-    }
-
-    explicit PositionFilename(const QString &p) : PositionFilenameType(p.data())
-    {
-    }
-
-    QString toString() const
-    {
-        QString result;
-        for(unsigned int i = 0; i < size(); i++)
-            result.append(at(i));
-        return result;
-    }
-};
-
-inline QDebug operator<<(QDebug out, const PositionFilename &p)
-{
-    out << p.toString();
-    return out;
-}
-
+typedef QString PositionFilename;
 typedef boost::spirit::classic::file_position_base<PositionFilename> PositionType;
 
 class Position : public PositionType
diff --git a/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp b/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp
index e488e4c..8c4a65f 100644
--- a/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp
+++ b/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp
@@ -591,7 +591,7 @@ void PreprocessLexer::dumpToFile()
     if (!d.exists())
         d.mkdir(tempPath);
 
-    QString fileName = tempPath + '/' + currentPosition().file.toString().replace(QRegExp("[/:mn]"), "-");
+    QString fileName = tempPath + '/' + currentPosition().file.replace(QRegExp("[/:mn]"), "-");
     QFile f(fileName);
     if (f.open(QIODevice::WriteOnly | QIODevice::Text)) {
         QTextStream out(&f);
-- 
1.8.4.2



More information about the umbrello-devel mailing list