umbrello API Documentation

cppimport.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *  copyright (C) 2005-2007                                                *
00009  *  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                   *
00010  ***************************************************************************/
00011 
00012 // own header
00013 #include "cppimport.h"
00014 // qt/kde includes
00015 #include <qmap.h>
00016 #include <qregexp.h>
00017 #include <kapplication.h>
00018 #include <kmessagebox.h>
00019 #include <kdebug.h>
00020 // app includes
00021 #include "import_utils.h"
00022 #include "../umlobject.h"
00023 #include "../docwindow.h"
00024 #include "../package.h"
00025 #include "../enum.h"
00026 #include "../classifier.h"
00027 #include "../operation.h"
00028 #include "../attribute.h"
00029 #include "../template.h"
00030 #include "../association.h"
00031 #include "kdevcppparser/lexer.h"
00032 #include "kdevcppparser/driver.h"
00033 #include "kdevcppparser/cpptree2uml.h"
00034 
00035 // static members
00036 CppDriver * CppImport::ms_driver;
00037 QStringList CppImport::ms_seenFiles;
00038 
00039 class CppDriver : public Driver {
00040 public:
00041     void setupLexer(Lexer* lexer) {
00042         Driver::setupLexer(lexer);
00043         lexer->setRecordComments(true);
00044     }
00045 };
00046 
00047 CppImport::CppImport() {
00048     ms_driver = new CppDriver();
00049 }
00050 
00051 CppImport::~CppImport() {}
00052 
00053 void CppImport::feedTheModel(const QString& fileName) {
00054     if (ms_seenFiles.find(fileName) != ms_seenFiles.end())
00055         return;
00056     ms_seenFiles.append(fileName);
00057     QMap<QString, Dependence> deps = ms_driver->dependences(fileName);
00058     if (! deps.empty()) {
00059         QMap<QString, Dependence>::Iterator it;
00060         for (it = deps.begin(); it != deps.end(); ++it) {
00061             if (it.data().second == Dep_Global)  // don't want these
00062                 continue;
00063             QString includeFile = it.key();
00064             if (includeFile.isEmpty()) {
00065                 kError() << fileName << ": " << it.data().first
00066                 << " not found" << endl;
00067                 continue;
00068             }
00069             kDebug() << fileName << ": " << includeFile << " => " << it.data().first << endl;
00070             if (ms_seenFiles.find(includeFile) == ms_seenFiles.end())
00071                 feedTheModel(includeFile);
00072         }
00073     }
00074     TranslationUnitAST *ast = ms_driver->translationUnit( fileName );
00075     if (ast == NULL) {
00076         kError() << "CppImport::feedTheModel: " << fileName << " not found" << endl;
00077         return;
00078     }
00079     CppTree2Uml modelFeeder( fileName );
00080     modelFeeder.parseTranslationUnit( ast );
00081 }
00082 
00083 void CppImport::initialize() {
00084     // Reset the driver
00085     ms_driver->reset();
00086     // The driver shall attempt to parse included files.
00087     ms_driver->setResolveDependencesEnabled( true );
00088     // Add some standard include paths
00089     ms_driver->addIncludePath( "/usr/include" );
00090     ms_driver->addIncludePath( "/usr/include/c++" );
00091     ms_driver->addIncludePath( "/usr/include/g++" );
00092     ms_driver->addIncludePath( "/usr/local/include" );
00093     QStringList incPathList = Import_Utils::includePathList();
00094     if (incPathList.count()) {
00095         QStringList::Iterator end(incPathList.end());
00096         for (QStringList::Iterator i(incPathList.begin()); i != end; ++i) {
00097             ms_driver->addIncludePath( *i );
00098         }
00099 
00100     }
00101     ms_seenFiles.clear();
00102 }
00103 
00104 void CppImport::parseFile(const QString& fileName) {
00105     if (ms_seenFiles.find(fileName) != ms_seenFiles.end())
00106         return;
00107     ms_driver->parseFile( fileName );
00108     feedTheModel(fileName);
00109 }
00110 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:56 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003