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

Ralf Habacker ralf.habacker at gmail.com
Mon Jul 2 16:38:37 UTC 2012


SVN commit 1303762 by habacker:

Cancel file import in case of internal lexer errors and print a related error message. It is better to have a single file not imported instead of an application freeze. Remaining parse problems could be fixed now easier.

BUG: 302671

 M  +2 -1      cppimport.cpp  
 M  +6 -4      kdevcppparser/driver.cpp  
 M  +1 -1      kdevcppparser/driver.h  
 M  +7 -4      kdevcppparser/lexer.cpp  
 M  +2 -2      kdevcppparser/lexer.h  
 M  +8 -1      kdevcppparser/preprocesslexer.cpp  
 M  +1 -1      kdevcppparser/preprocesslexer.h  


--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/cppimport.cpp #1303761:1303762
@@ -133,7 +133,8 @@
 {
     if (ms_seenFiles.indexOf(fileName) != -1)
         return true;
-    ms_driver->parseFile( fileName );
+    if (!ms_driver->parseFile( fileName ))
+        return false;
     feedTheModel(fileName);
     return true;
 }
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/driver.cpp #1303761:1303762
@@ -211,7 +211,7 @@
     return QList<Problem>();
 }
 
-void Driver::parseFile( const QString& fileName, bool onlyPreProcess, bool force )
+bool Driver::parseFile( const QString& fileName, bool onlyPreProcess, bool force )
 {
     QFileInfo fileInfo( fileName );
     QString absoluteFilePath = fileInfo.absoluteFilePath();
@@ -222,7 +222,7 @@
         takeTranslationUnit( absoluteFilePath );
     } else if( it != m_parsedUnits.end() && *it != 0 ){
         // file already processed
-        return;
+        return true;
     }
 
     m_dependences.remove( fileName );
@@ -234,8 +234,9 @@
     lexer = &lex;
     setupLexer( &lex );
 
-    lex.setSource( sourceProvider()->contents(fileName),
-                   QString2PositionFilename( fileName));
+    if (!lex.setSource( sourceProvider()->contents(fileName),
+                   QString2PositionFilename( fileName)))
+        return false;
 
     if( !onlyPreProcess ){
         Parser parser( this, &lex );
@@ -249,6 +250,7 @@
 
     m_currentFileName.clear();
     lexer = 0;
+    return true;
 }
 
 void Driver::setupLexer( Lexer * lexer )
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/driver.h #1303761:1303762
@@ -170,7 +170,7 @@
 
     virtual void reset();
 
-    virtual void parseFile( const QString& fileName, bool onlyPreProcesss=false, bool force=false );
+    virtual bool parseFile( const QString& fileName, bool onlyPreProcesss=false, bool force=false );
     virtual void fileParsed( const QString& fileName );
     virtual void addDependence( const QString& fileName, const Dependence& dep );
     virtual void addMacro( const Macro& macro) {m_macroManager.addMacro( macro);}
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/lexer.cpp #1303761:1303762
@@ -324,13 +324,14 @@
 {
 }
 
-void Lexer::setSource(const QString& source,
+bool Lexer::setSource(const QString& source,
                       PositionFilename const& p_filename)
 {
     reset();
     m_preprocessLexer.setSource(source, p_filename);
     m_source.set_filename(p_filename);
-    tokenize();
+    return tokenize();
+
 }
 
 void Lexer::reset()
@@ -397,9 +398,10 @@
         m_source.set_startLine(false);
 }
 
-void Lexer::tokenize()
+bool Lexer::tokenize()
 {
-    m_preprocessLexer.preprocess();
+    if (!m_preprocessLexer.preprocess())
+        return false;
 #if 0
     QByteArray l_tmp = m_preprocessLexer.preprocessedString().toAscii();
     for (int i = 0; i < l_tmp.size(); ++i)
@@ -421,6 +423,7 @@
 
     Token tk = m_source.createToken(Token_eof, m_source.get_ptr());
     m_tokens.push_back(tk);
+    return true;
 }
 
 void Lexer::handleDirective(const QString& directive)
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/lexer.h #1303761:1303762
@@ -71,7 +71,7 @@
                      const QString& str = QString())
     { m_preprocessLexer.addSkipWord( word, skipType, str); }
 
-    void setSource( const QString& source, PositionFilename const& p_filename);
+    bool setSource( const QString& source, PositionFilename const& p_filename);
     void setRecordComments( bool record );
     Position currentPosition() const { return m_source.get_currentPosition(); }
 
@@ -83,7 +83,7 @@
     Position const& getTokenPosition(const Token& token) const;
     TokenIterator tokenBegin() const {return m_tokens.begin();}
 private:
-    void tokenize();
+    bool tokenize();
     void nextToken(Token& token);
     bool recordComments() const;
     void reset();
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp #1303761:1303762
@@ -579,16 +579,23 @@
         m_preprocessedString += *p_first;
 }
 
-void PreprocessLexer::preprocess()
+bool PreprocessLexer::preprocess()
 {
     for (;;) {
+        Position start = currentPosition();
         nextLine();
+        if (currentPosition() == start) {
+            uError() << "failed to preprocess file" << start;
+            return false;
+        }
+
         if (m_source.currentChar().isNull())
             break;
     }
 
     Token tk = m_source.createToken(Token_eof, m_source.get_ptr());
     m_preprocessedString += tk.text();
+    return true;
 }
 
 void PreprocessLexer::addSkipWord(const QString& word, SkipType skipType, const QString& str)
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.h #1303761:1303762
@@ -201,7 +201,7 @@
 
     void addSkipWord( const QString& word, SkipType skipType = SkipWord,
                       const QString& str = QString() );
-    void preprocess();
+    bool preprocess();
     void setSource( const QString& source, PositionFilename const& p_filename);
     void setRecordComments( bool record );
     QString const& preprocessedString() const {return m_preprocessedString;}




More information about the umbrello-devel mailing list