[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport
Oliver Kellogg
okellogg at users.sourceforge.net
Wed Jan 10 20:12:45 UTC 2007
SVN commit 622128 by okellogg:
Support renamed packages.
m_renaming: New map that stores package renamings.
expand(): New. Expands a renaming to the original long package name.
M +27 -9 adaimport.cpp
M +24 -2 adaimport.h
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/adaimport.cpp #622127:622128
@@ -5,8 +5,8 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2005-2006 *
- * Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
+ * copyright (C) 2005-2007 *
+ * Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
// own header
@@ -36,6 +36,7 @@
void AdaImport::initVars() {
m_inGenericFormalPart = false;
m_classesDefinedInThisScope.clear();
+ m_renaming.clear();
}
/// Split the line so that a string is returned as a single element of the list,
@@ -117,6 +118,20 @@
m_source.append(lexeme);
}
+QString AdaImport::expand(const QString& name) {
+ QRegExp pfxRegExp("^(\\w+)\\.");
+ int pos = pfxRegExp.search(name);
+ if (pos == -1)
+ return name;
+ QString result = name;
+ QString pfx = pfxRegExp.cap(1);
+ if (m_renaming.contains(pfx)) {
+ result.remove(pfxRegExp);
+ result.prepend(m_renaming[pfx] + '.');
+ }
+ return result;
+}
+
bool AdaImport::parseStmt() {
const uint srcLength = m_source.count();
const QString& keyword = m_source[m_srcIndex];
@@ -170,16 +185,18 @@
}
if (keyword == "package") {
const QString& name = advance();
- UMLObject *ns = Import_Utils::createUMLObject(Uml::ot_Package, name,
- m_scope[m_scopeIndex], m_comment);
if (advance() == "is") {
+ UMLObject *ns = Import_Utils::createUMLObject(Uml::ot_Package, name,
+ m_scope[m_scopeIndex], m_comment);
if (m_source[m_srcIndex + 1] == "new") {
// generic package instantiation: TBD
skipStmt();
} else {
m_scope[++m_scopeIndex] = static_cast<UMLPackage*>(ns);
}
- } else if (m_source[m_srcIndex] != "renames") {
+ } else if (m_source[m_srcIndex] == "renames") {
+ m_renaming[name] = advance();
+ } else {
kError() << "AdaImport::parseStmt: unexpected: " << m_source[m_srcIndex] << endl;
skipStmt("is");
}
@@ -235,8 +252,8 @@
m_srcIndex++;
}
if (m_source[m_srcIndex] == "tagged") {
+ isTaggedType = true;
m_srcIndex++;
- isTaggedType = true;
}
if (m_source[m_srcIndex] == "limited") {
m_srcIndex++; // we can't (yet?) represent that
@@ -262,7 +279,7 @@
return true;
}
if (m_source[m_srcIndex] == "new") {
- QString base = advance();
+ QString base = expand(advance());
const bool isExtension = (advance() == "with");
Uml::Object_Type t = (isExtension || m_isAbstract ? Uml::ot_Class
: Uml::ot_Datatype);
@@ -367,6 +384,7 @@
typeName = direction; // In Ada, the default direction is "in"
}
typeName.remove("Standard.", false);
+ typeName = expand(typeName);
if (op == NULL) {
// In Ada, the first parameter indicates the class.
UMLDoc *umldoc = UMLApp::app()->getDocument();
@@ -415,7 +433,7 @@
<< name << endl;
return false;
}
- returnType = advance();
+ returnType = expand(advance());
returnType.remove("Standard.", false);
}
bool isAbstract = false;
@@ -477,7 +495,7 @@
skipStmt();
return true;
}
- QString typeName = advance();
+ QString typeName = expand(advance());
QString initialValue;
if (advance() == ":=") {
initialValue = advance();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codeimport/adaimport.h #622127:622128
@@ -5,13 +5,14 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2005-2006 *
- * Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
+ * copyright (C) 2005-2007 *
+ * Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
#ifndef ADAIMPORT_H
#define ADAIMPORT_H
+#include <qmap.h>
#include "nativeimportbase.h"
#include "../umlobjectlist.h"
@@ -50,9 +51,30 @@
*/
void fillSource(const QString& word);
+ /**
+ * Apply package renamings to the given name.
+ *
+ * @return expanded name
+ */
+ QString expand(const QString& name);
+
bool m_inGenericFormalPart; ///< auxiliary variable
+ /**
+ * List for keeping track of tagged objects declared in the current scope.
+ * This is required for distinguishing primitive from non primitive
+ * methods.
+ */
UMLObjectList m_classesDefinedInThisScope;
+
+ typedef QMap<QString, QString> StringMap;
+
+ /**
+ * Map of package renamings.
+ * Keyed by the renaming. Value returns the expanded name.
+ */
+ StringMap m_renaming;
+
};
#endif
More information about the umbrello-devel
mailing list