[Uml-devel] branches/work/soc-umbrello/umbrello/codeimport
Andi Fischer
andi.fischer at hispeed.ch
Mon Jan 16 21:29:53 UTC 2012
SVN commit 1274018 by fischer:
Changes in trunk also applied.
M +9 -6 classimport.cpp
M +2 -2 classimport.h
M +1 -0 cppimport.cpp
M +2 -1 csharp/csharpimport.h
M +5 -0 idlimport.cpp
M +17 -0 import_utils.cpp
M +6 -0 kdevcppparser/ast.cpp
M +27 -0 kdevcppparser/ast.h
M +7 -0 kdevcppparser/cpptree2uml.cpp
M +1 -0 kdevcppparser/cpptree2uml.h
M +21 -2 kdevcppparser/parser.cpp
M +10 -0 kdevcppparser/tree_parser.cpp
M +1 -0 kdevcppparser/tree_parser.h
--- branches/work/soc-umbrello/umbrello/codeimport/classimport.cpp #1274017:1274018
@@ -47,7 +47,7 @@
else if (fileName.contains(QRegExp("\\.ad[sba]$")))
classImporter = new AdaImport(thread);
else if (fileName.endsWith(QLatin1String(".pas")))
- classImporter = new PascalImport();
+ classImporter = new PascalImport(thread);
else if (fileName.endsWith(QLatin1String(".cs")))
classImporter = new CSharpImport(thread);
#ifndef DISABLE_CPP_IMPORT
@@ -64,28 +64,31 @@
* Import files. :TODO: can be deleted
* @param fileNames List of files to import.
*/
-void ClassImport::importFiles(const QStringList& fileNames)
+bool ClassImport::importFiles(const QStringList& fileNames)
{
initialize();
UMLDoc *umldoc = UMLApp::app()->document();
uint processedFilesCount = 0;
+ bool result = true;
foreach (const QString& fileName, fileNames) {
umldoc->writeToStatusBar(i18n("Importing file: %1 Progress: %2/%3",
fileName, processedFilesCount, fileNames.size()));
- parseFile(fileName);
+ if (!parseFile(fileName))
+ result = false;
processedFilesCount++;
}
- umldoc->writeToStatusBar(i18nc("ready to status bar", "Ready."));
+ umldoc->writeToStatusBar(result ? i18nc("ready to status bar", "Ready.") : i18nc("failed to status bar", "Failed."));
+ return result;
}
/**
* Import files.
* @param files List of files to import.
*/
-void ClassImport::importFile(const QString& fileName)
+bool ClassImport::importFile(const QString& fileName)
{
initialize();
- parseFile(fileName);
+ return parseFile(fileName);
}
/**
--- branches/work/soc-umbrello/umbrello/codeimport/classimport.h #1274017:1274018
@@ -28,8 +28,8 @@
ClassImport(CodeImpThread* thread = 0) : m_thread(thread), m_enabled(true) {}
virtual ~ClassImport() {}
- void importFiles(const QStringList& fileNames);
- void importFile(const QString& fileName);
+ bool importFiles(const QStringList& fileNames);
+ bool importFile(const QString& fileName);
/**
* Return state of the importer. It may be disabled because of
--- branches/work/soc-umbrello/umbrello/codeimport/cppimport.cpp #1274017:1274018
@@ -109,6 +109,7 @@
ms_driver->reset();
// The driver shall attempt to parse included files.
ms_driver->setResolveDependencesEnabled( true );
+ // FIXME: port to win32
// Add some standard include paths
ms_driver->addIncludePath( "/usr/include" );
ms_driver->addIncludePath( "/usr/include/c++" );
--- branches/work/soc-umbrello/umbrello/codeimport/csharp/csharpimport.h #1274017:1274018
@@ -16,7 +16,8 @@
class UMLObject;
/**
- * C# code import
+ * C# code import.
+ * Grammar of C# can be found at @ref http://msdn.microsoft.com/en-us/library/Aa664812 .
* @author Andi Fischer (copied from JavaImport)
* Bugs and comments to uml-devel at lists.sf.net or http://bugs.kde.org
*/
--- branches/work/soc-umbrello/umbrello/codeimport/idlimport.cpp #1274017:1274018
@@ -178,6 +178,11 @@
uError() << "could not run preprocessor";
return false;
}
+ int exitCode = p.exitCode();
+ if (exitCode != 0) {
+ uError() << "preprocessor returned error" << exitCode;
+ return false;
+ }
QByteArray out = p.readAllStandardOutput();
QTextStream data(out);
--- branches/work/soc-umbrello/umbrello/codeimport/import_utils.cpp #1274017:1274018
@@ -13,6 +13,7 @@
// app includes
#include "association.h"
+#include "artifact.h"
#include "attribute.h"
#include "classifier.h"
#include "debug_utils.h"
@@ -26,6 +27,7 @@
#include "uml.h"
#include "umldoc.h"
#include "umlobject.h"
+#include "umbrellosettings.h"
// kde includes
#include <kmessagebox.h>
@@ -168,6 +170,21 @@
{
QString name = inName;
UMLDoc *umldoc = UMLApp::app()->document();
+ if (type == UMLObject::ot_Artifact) {
+ if (!Settings::optionState().codeImportState.createArtifacts)
+ return 0;
+ QFileInfo fi(name);
+ UMLFolder *componentView = umldoc->rootFolder(Uml::ModelType::Component);
+ UMLObject *o = umldoc->findUMLObjectRaw(componentView, fi.fileName(), type);
+ if (o)
+ return o;
+ o = Object_Factory::createUMLObject(type, fi.fileName(), componentView, false);
+ UMLArtifact *a = static_cast<UMLArtifact*>(o);
+ a->setDrawAsType(UMLArtifact::file);
+ a->setDoc(comment);
+ uDebug() << name << comment;
+ return o;
+ }
UMLFolder *logicalView = umldoc->rootFolder(Uml::ModelType::Logical);
if (parentPkg == NULL) {
// uDebug() << "Import_Utils::createUMLObject(" << name
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/ast.cpp #1274017:1274018
@@ -228,6 +228,12 @@
// ------------------------------------------------------------------------
+FileAST::FileAST()
+{
+}
+
+// ------------------------------------------------------------------------
+
LinkageBodyAST::LinkageBodyAST()
{
}
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/ast.h #1274017:1274018
@@ -171,6 +171,7 @@
NodeType_TemplateParameter,
NodeType_TemplateParameterList,
NodeType_Condition,
+ NodeType_File,
NodeType_Custom = 2000
};
@@ -422,6 +423,32 @@
void operator = ( const DeclarationAST& source );
};
+class FileAST: public DeclarationAST
+{
+public:
+ typedef AUTO_PTR<FileAST> Node;
+ enum { Type = NodeType_File };
+
+ DECLARE_ALLOC( FileAST )
+
+ public:
+ FileAST();
+
+ QString fileName() { return m_fileName; }
+ void setFileName(QString fileName) { m_fileName = fileName; }
+
+ QList<AST*> nodeList() { return m_nodeList; }
+ void addNode( AST::Node& node );
+
+private:
+ QList<AST*> m_nodeList;
+ QString m_fileName;
+
+private:
+ FileAST( const FileAST& source );
+ void operator = ( const FileAST& source );
+};
+
class AccessDeclarationAST: public DeclarationAST
{
public:
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/cpptree2uml.cpp #1274017:1274018
@@ -60,6 +60,13 @@
TreeParser::parseTranslationUnit( ast );
}
+void CppTree2Uml::parseFile( FileAST* ast )
+{
+ Import_Utils::createUMLObject(UMLObject::ot_Artifact, ast->fileName(),
+ 0,
+ ast->comment());
+}
+
void CppTree2Uml::parseNamespace( NamespaceAST* ast )
{
if (m_clsCnt > 0) {
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/cpptree2uml.h #1274017:1274018
@@ -36,6 +36,7 @@
// declarations
//virtual void parseDeclaration( DeclarationAST* ); // use parent method
//virtual void parseLinkageSpecification( LinkageSpecificationAST* ); // use parent method
+ virtual void parseFile( FileAST* ast );
virtual void parseNamespace( NamespaceAST* );
//virtual void parseNamespaceAlias( NamespaceAliasAST* ); // use parent method
//virtual void parseUsing( UsingAST* ); // use parent method
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/parser.cpp #1274017:1274018
@@ -69,7 +69,6 @@
lex(lexer)
{
d = new ParserPrivateData();
-
m_maxProblems = 5;
objcp = false;
}
@@ -422,13 +421,33 @@
{
//uDebug() << "--- tok = " << (*m_tokenIt).text() << " -- " << "Parser::parseDeclaration()";
+ // catch first comment
+ Position ps = m_tokenIt->getStartPosition();
+ if (ps.line == 1 && ps.column == 1)
+ {
+ FileAST::Node ast = CreateNode<FileAST>();
+ ast->setFileName(m_driver->currentFileName());
+ QString comment = (*m_tokenIt).text();
+
+ if ((*m_tokenIt) == Token_comment) {
+ ast->setComment(comment);
+ ++m_tokenIt;
+ }
+ uDebug() << m_driver->currentFileName() << comment;
+ node = ast;
+ return true;
+ }
+
QString comment;
while ((*m_tokenIt) == Token_comment) {
comment += (*m_tokenIt).text();
++m_tokenIt;
}
- if ((*m_tokenIt).isNull())
+
+ if ((*m_tokenIt).isNull()) {
+ // FIXME: add fetched comment to FileAST
return false;
+ }
TokenIterator start = m_tokenIt;
bool success = false;
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/tree_parser.cpp #1274017:1274018
@@ -47,6 +47,10 @@
return;
switch (declaration->nodeType()) {
+ case NodeType_File:
+ parseFile(static_cast<FileAST*>(declaration));
+ break;
+
case NodeType_LinkageSpecification:
parseLinkageSpecification(static_cast<LinkageSpecificationAST*>(declaration));
break;
@@ -89,6 +93,12 @@
}
}
+void TreeParser::parseFile(FileAST* decl)
+{
+ //uDebug() << "TreeParser::parseFile()";
+ Q_UNUSED(decl);
+}
+
void TreeParser::parseLinkageSpecification(LinkageSpecificationAST* ast)
{
//uDebug() << "TreeParser::parseLinkageSpecification()";
--- branches/work/soc-umbrello/umbrello/codeimport/kdevcppparser/tree_parser.h #1274017:1274018
@@ -33,6 +33,7 @@
// declarations
virtual void parseDeclaration( DeclarationAST* );
+ virtual void parseFile( FileAST* );
virtual void parseLinkageSpecification( LinkageSpecificationAST* );
virtual void parseNamespace( NamespaceAST* );
virtual void parseNamespaceAlias( NamespaceAliasAST* );
More information about the umbrello-devel
mailing list