Commit 3b638620 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

umbrello/uml.cpp

- In function setGenerator() revert part of commit ea25b643 which returns
  preexisting m_codegen if (m_codegen->language() == pl).

umbrello/codegenerators/codegenerator.{h,cpp}
- New virtual function finalizeRun() with empty default implementation can
  be reimplemented by concrete code generators to perform additional
  cleanups or other actions that can only be performed once all code has
  been written. The function is called in writeCodeToFile() after return
  from writeListedCodeDocsToFile().

umbrello/codegenerators/simplecodegenerator.cpp
- In function writeCodeToFile(), utilize writeCodeToFile(concepts) for
  minimizing code duplication.
- In function writeCodeToFile(UMLClassifierList&),
  - do not writeClass(c) if Model_Utils::isCommonDataType(c->name());
  - call finalizeRun() after foreach loop over `concepts'.

umbrello/codegenerators/ada/adawriter.{h,cpp}
- Add `static' on declaration of functions isOOClass() and packageName().
- New function declareClass() factors trunk of Ada declaration which is
  common to partial (public) and full (private) view.
- Reimplement function finalizeRun() from CodeGenerator: Cumulative
  generation of the private part is moved from writeClass() to here.
- New member m_pkgsGenerated is required for closing opened files in
  finalizeRun().
- New member m_classesGenerated is required for ensuring that order of code
  generation is consistent with order of dependencies among classifiers in
  the package.

umbrello/codegenerators/ada/adawriter.cpp function writeClass()
- Return immediately without further action if `c' is already present in
  m_classesGenerated.
- If `pkg' is found in m_pkgsGenerated then do not open file / write
  initial declarations but instead use the value() of the PackageFileMap::
  iterator found for `file'.
- If `pkg' is found in m_pkgsGenerated then:
  - Open file and write initial declarations; in loop over `imports', do not
    write "with" if packageName(con) does not match `pkg'.
  - Assign `file' into m_pkgsGenerated[pkg].
- Before declaring the Ada type mapped from `c', loop over
  c->getSuperClasses() and ensure that superclasses in same package are
  written beforehand.
- Move all aggregation/composition/attribute handling to finalizeRun().

umbrello/codegenerators/ada/adawriter.cpp function reservedKeywords()
- Add Ada2005 reserved word "interface".

BUG:336933
parent ed9ddf60
This diff is collapsed.
......@@ -13,10 +13,14 @@
#define ADAWRITER_H
#include "simplecodegenerator.h"
#include "umlclassifierlist.h"
#include <QMap>
class UMLAssociation;
class UMLOperation;
class QTextStream;
class QFile;
/**
* Class AdaWriter is a code generator for UMLClassifier objects.
......@@ -45,20 +49,38 @@ public:
private:
void declareClass(UMLClassifier *c, QTextStream &ada);
void writeOperation(UMLOperation *op, QTextStream &ada, bool is_comment = false);
void computeAssocTypeAndRole(UMLClassifier *c,
UMLAssociation *a,
QString& typeName, QString& roleName);
bool isOOClass(UMLClassifier *c);
static bool isOOClass(UMLClassifier *c);
QString className(UMLClassifier *c, bool inOwnScope = true);
QString packageName(UMLPackage *p);
static QString packageName(UMLPackage *p);
void finalizeRun();
static const QString defaultPackageSuffix;
typedef QMap<QString, QFile*> PackageFileMap;
/**
* Map package name to QFile.
* Required for closing opened files in finalizeRun().
*/
PackageFileMap m_pkgsGenerated;
/**
* List of classifiers generated.
* Required for ensuring order of code generation which
* satisfies order of dependencies among classifiers.
*/
UMLClassifierList m_classesGenerated;
};
#endif // ADAWRITER_H
......@@ -390,6 +390,7 @@ CodeDocument * CodeGenerator::findCodeDocumentByClassifier(UMLClassifier * class
void CodeGenerator::writeCodeToFile()
{
writeListedCodeDocsToFile(&m_codedocumentVector);
finalizeRun();
}
/**
......@@ -409,6 +410,7 @@ void CodeGenerator::writeCodeToFile(UMLClassifierList & concepts)
}
writeListedCodeDocsToFile(&docs);
finalizeRun();
}
// Main method. Will write out passed code documents to file as appropriate.
......@@ -451,6 +453,19 @@ void CodeGenerator::writeListedCodeDocsToFile(CodeDocumentList * docs)
}
}
/**
* A single call to writeCodeToFile() usually entails processing many
* items (e.g. as classifiers) for which code is generated.
* This method is called after all code of one call to writeCodeToFile()
* has been generated.
* It can be reimplemented by concrete code generators to perform additional
* cleanups or other actions that can only be performed once all code has
* been written.
*/
void CodeGenerator::finalizeRun()
{
}
/**
* Create a new Code document belonging to this package.
* @return CodeDocument pointer to new code document.
......
......@@ -174,6 +174,8 @@ protected:
void writeListedCodeDocsToFile(CodeDocumentList * docs);
virtual void finalizeRun();
// map of what code documents we currently have in this generator.
QHash<QString, CodeDocument*> m_codeDocumentDictionary;
......
......@@ -280,12 +280,8 @@ CodeDocument * SimpleCodeGenerator::newClassifierCodeDocument(UMLClassifier* cla
*/
void SimpleCodeGenerator::writeCodeToFile()
{
m_fileMap.clear(); // need to do this, else just keep getting same directory to write to.
UMLClassifierList concepts = m_document->classesAndInterfaces();
foreach (UMLClassifier* c, concepts) {
if (! Model_Utils::isCommonDataType(c->name()))
this->writeClass(c); // call the writer for each class.
}
writeCodeToFile(concepts);
}
/**
......@@ -296,8 +292,10 @@ void SimpleCodeGenerator::writeCodeToFile(UMLClassifierList & concepts)
{
m_fileMap.clear(); // ??
foreach (UMLClassifier* c, concepts) {
this->writeClass(c); // call the writer for each class.
if (! Model_Utils::isCommonDataType(c->name()))
this->writeClass(c); // call the writer for each class.
}
finalizeRun();
}
/**
......
......@@ -2245,12 +2245,11 @@ CodeGenerator *UMLApp::setGenerator(Uml::ProgrammingLanguage::Enum pl)
}
return NULL;
}
// does the code generator already exist?
// then simply return that
if (m_codegen) {
if (m_codegen->language() == pl) {
return m_codegen;
}
// Do not return a possible preexisting code generator:
// if (m_codegen->language() == pl) return m_codegen;
// Some languages depend on a new generator instance being created
// for each run.
delete m_codegen; // ATTENTION! remove all refs to it or its policy first
m_codegen = NULL;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment