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

Ralf Habacker ralf.habacker at gmail.com
Sat Jul 7 09:22:47 UTC 2012


SVN commit 1304416 by habacker:

Merged 1303762 from trunk

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.

 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  


--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/cppimport.cpp #1304415:1304416
@@ -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;
 }
--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/driver.cpp #1304415:1304416
@@ -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 )
--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/driver.h #1304415:1304416
@@ -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);}
--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/lexer.cpp #1304415:1304416
@@ -313,13 +313,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()
@@ -386,9 +387,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)
@@ -410,6 +412,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)
--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/lexer.h #1304415:1304416
@@ -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();
--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.cpp #1304415:1304416
@@ -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)
--- branches/KDE/4.9/kdesdk/umbrello/umbrello/codeimport/kdevcppparser/preprocesslexer.h #1304415:1304416
@@ -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