[Uml-devel] branches/work/soc-umbrello/umbrello

Andi Fischer andi.fischer at hispeed.ch
Mon Jul 9 06:58:06 UTC 2012


SVN commit 1304691 by fischer:

Commits from trunk applied. Diff to trunk reduced.

 M  +1 -2      codeimport/kdevcppparser/driver.cpp  
 M  +3 -3      codeimport/kdevcppparser/lexer.cpp  
 M  +0 -1      codeimport/kdevcppparser/lexer.h  
 M  +87 -12    codeimport/kdevcppparser/position.h  
 M  +37 -3     codeimport/kdevcppparser/preprocesslexer.cpp  
 M  +3 -1      codeimport/kdevcppparser/preprocesslexer.h  
 M  +1 -1      widgets/artifactwidget.cpp  
 M  +1 -1      widgets/categorywidget.h  
 M  +1 -1      widgets/componentwidget.cpp  


--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/driver.cpp #1304690:1304691
@@ -234,8 +234,7 @@
     lexer = &lex;
     setupLexer( &lex );
 
-    if (!lex.setSource( sourceProvider()->contents(fileName),
-                   QString2PositionFilename( fileName)))
+    if (!lex.setSource( sourceProvider()->contents(fileName), fileName))
         return false;
 
     if( !onlyPreProcess ){
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/lexer.cpp #1304690:1304691
@@ -28,6 +28,7 @@
 #include <QtCore/QRegExp>
 #include <QtCore/QMap>
 #include <QtCore/QList>
+#include <QtCore/QChar>
 
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
@@ -174,8 +175,7 @@
         definition(charLiteral const& self) {
             main =
                 (!ch_p('L') >> ch_p('\'')
-                 >> *((anychar_p - '\'' - '\\')
-                 | (ch_p('\\') >> (ch_p('\'') | '\\' | 'n' | '0')))
+                 >> *((anychar_p - '\'' - '\\') | gr_escapeSequence )
                  >> '\'')
                 [ self.result_ = construct_<Token>(Token_char_literal, arg1, arg2)];
         }
@@ -210,7 +210,7 @@
 };
 
 Lexer::CharRule gr_stringLiteral =
-    ch_p('"') >> *((anychar_p - '"' - '\\') | str_p("\\\"") | "\\\\" | "\\n") >> '"';
+    ch_p('"') >> *((anychar_p - '"' - '\\') | gr_escapeSequence ) >> '"';
 Lexer::CharRule gr_whiteSpace = blank_p | (ch_p('\\') >> eol_p);
 Lexer::CharRule gr_lineComment = (str_p("//") >> (*(anychar_p - eol_p)));
 Lexer::CharRule gr_multiLineComment = confix_p("/*", *anychar_p, "*/");
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/lexer.h #1304690:1304691
@@ -49,7 +49,6 @@
 using boost::spirit::classic::scanner;
 using boost::spirit::classic::ext::skip_rule_parser;
 
-typedef boost::spirit::classic::position_iterator<QChar const*> CharIterator;
 typedef rule<scanner<CharIterator> > SkipRule;
 typedef skip_rule_parser<SkipRule, CharIterator> CharParser;
 typedef scanner<CharIterator> CharScanner;
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/position.h #1304690:1304691
@@ -43,33 +43,108 @@
 #include <QChar>
 #include <QDebug>
 
-typedef boost::spirit::classic::file_position_base<std::basic_string<QChar> > Position;
-typedef std::basic_string<QChar> PositionFilename;
+typedef std::basic_string<QChar> PositionFilenameType;
 
-inline PositionFilename QString2PositionFilename( QString const& p)
+class PositionFilename : public PositionFilenameType
 {
-    return p.data();
+public:
+    PositionFilename()
+    {
 }
 
+    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 boost::spirit::classic::file_position_base<PositionFilename> PositionType;
+
+class Position : public PositionType
+{
+public:
+    Position()
+    {
+    }
+
+    Position(const PositionFilename &p) : PositionType(p)
+    {
+    }
+
+    Position(const Position &p) : PositionType(p)
+    {
+    }
+
+    Position(const PositionType &p) : PositionType(p)
+    {
+    }
+
+    bool operator<(Position const& p) const
+    {
+        assert( file == p.file);
+        return( (line < p.line) || ( (line == p.line) && (column < p.column)));
+    }
+
+    bool operator>=(Position const& p) const
+    {
+        return !(*this < p);
+    }
+};
+
 inline QDebug operator<<(QDebug out, Position const &p)
 {
     out << "Position("
-        //<< "file" << p.file
-        << "line:" << p.line
-        << "column:" << p.column
+        << "file" << p.file
+        << "line" << p.line
+        << "column" << p.column
         << ")";
     return out;
 }
 
-inline bool operator<( Position const& p1, Position const& p2)
+typedef boost::spirit::classic::position_iterator<QChar const*, PositionType> CharIteratorType;
+
+class CharIterator : public CharIteratorType
 {
-    assert( p1.file == p2.file);
-    return( (p1.line < p2.line) || ( (p1.line == p2.line) && (p1.column < p2.column)));
+public:
+    CharIterator()
+    { 
 }
 
-inline bool operator>=( Position const& p1, Position const& p2)
+    CharIterator(const QChar *a, const QChar *b, Position p) : CharIteratorType(a,b,p)
 {
-    return !(p1 < p2);
 }
 
+    CharIterator(const PositionType &p) : CharIteratorType(0, 0, p)
+    {
+    }
+/*
+    CharIterator(PositionType p) : CharIteratorType(0, 0, p)
+    {
+    }
+*/
+    const Position &get_position() const
+    {
+        return static_cast<const Position&>(CharIteratorType::get_position());
+    }
+
+    void set_position(Position const& p)
+    {
+        CharIteratorType::set_position(p);
+    }
+};
+
+
 #endif
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp #1304690:1304691
@@ -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> {
@@ -168,8 +173,7 @@
         definition(charLiteral const& self) {
             main =
                 (!ch_p('L') >> ch_p('\'')
-                 >> *((anychar_p - '\'' - '\\')
-                      | (ch_p('\\') >> (ch_p('\'') | '\\')))
+                 >> *((anychar_p - '\'' - '\\') | gr_escapeSequence)
                  >> '\'')
                 [ self.result_ = construct_<Token>(Token_char_literal, arg1, arg2)];
         }
@@ -579,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;
         }
 
@@ -966,6 +992,14 @@
     return macroLogicalOr();
 }
 
+PreprocessLexer::CharRule gr_simpleEscapeSequence = (ch_p('\\') >> (ch_p('\\') | '"' | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' | '0' ));
+PreprocessLexer::CharRule gr_octalDigit = (ch_p('0') | '1' | '2' | '3' | '4' | '5' | '6' | '7');
+PreprocessLexer::CharRule gr_digit = (ch_p('0') | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9');
+PreprocessLexer::CharRule gr_hexDigit = (gr_digit | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f');
+PreprocessLexer::CharRule gr_octalEscapeSequence = (ch_p('\\') >> gr_octalDigit >> *gr_octalDigit);
+PreprocessLexer::CharRule gr_hexEscapeSequence = (ch_p('\\') >> ch_p('x') >> gr_hexDigit >> gr_hexDigit);
+PreprocessLexer::CharRule gr_escapeSequence = gr_simpleEscapeSequence | gr_octalEscapeSequence | gr_hexEscapeSequence;
+
 // *IMPORTANT* please, don't include preprocesslexer.moc here, because
 // PreprocessLexer isn't a QObject class!!  if you have problem while
 // recompiling try to remove cppsupport/.deps, cppsupport/Makefile.in
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.h #1304690:1304691
@@ -43,7 +43,6 @@
 using boost::spirit::classic::scanner;
 using boost::spirit::classic::ext::skip_rule_parser;
 
-typedef boost::spirit::classic::position_iterator<QChar const*> CharIterator;
 typedef rule<scanner<CharIterator> > SkipRule;
 typedef skip_rule_parser<SkipRule, CharIterator> CharParser;
 typedef scanner<CharIterator> CharScanner;
@@ -207,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(),
@@ -372,4 +372,6 @@
     m_recordComments = record;
 }
 
+extern PreprocessLexer::CharRule gr_escapeSequence;
+
 #endif
--- branches/work/soc-umbrello/umbrello/widgets/artifactwidget.cpp #1304690:1304691
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2003-2011                                               *
+ *   copyright (C) 2003-2012                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
--- branches/work/soc-umbrello/umbrello/widgets/categorywidget.h #1304690:1304691
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2002-2006                                               *
+ *   copyright (C) 2002-2012                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 
--- branches/work/soc-umbrello/umbrello/widgets/componentwidget.cpp #1304690:1304691
@@ -4,7 +4,7 @@
  *   the Free Software Foundation; either version 2 of the License, or     *
  *   (at your option) any later version.                                   *
  *                                                                         *
- *   copyright (C) 2003-2011                                               *
+ *   copyright (C) 2003-2012                                               *
  *   Umbrello UML Modeller Authors <uml-devel at uml.sf.net>                  *
  ***************************************************************************/
 




More information about the umbrello-devel mailing list