Commit d4f45447 authored by Ralf Habacker's avatar Ralf Habacker
Browse files

Write out typedefs located in classes for default code generator.

CCBUG:371274
parent 828f7dac
......@@ -17,6 +17,7 @@
#include "association.h"
#include "classifier.h"
#include "codegen_utils.h"
#include "datatype.h"
#include "debug_utils.h"
#include "model_utils.h"
#include "uml.h"
......@@ -450,6 +451,7 @@ void CppWriter::writeClassDecl(UMLClassifier *c, QTextStream &cpp)
// PUBLIC attribs/methods
cpp << "public:" << m_endl << m_endl; // print visibility decl.
writeDataTypes(c, Uml::Visibility::Public, cpp);
// for public: constructors are first ops we print out
if (!c->isInterface())
writeConstructorDecls(cpp);
......@@ -460,6 +462,7 @@ void CppWriter::writeClassDecl(UMLClassifier *c, QTextStream &cpp)
// PROTECTED attribs/methods
//
cpp << "protected" << ":" << m_endl << m_endl; // print visibility decl.
writeDataTypes(c, Uml::Visibility::Protected, cpp);
writeHeaderFieldDecl(c, Uml::Visibility::Protected, cpp);
writeHeaderAccessorMethodDecl(c, Uml::Visibility::Protected, cpp);
writeOperations(c, true, Uml::Visibility::Protected, cpp);
......@@ -467,6 +470,7 @@ void CppWriter::writeClassDecl(UMLClassifier *c, QTextStream &cpp)
// PRIVATE attribs/methods
//
cpp << "private" << ":" << m_endl << m_endl; // print visibility decl.
writeDataTypes(c, Uml::Visibility::Private, cpp);
writeHeaderFieldDecl(c, Uml::Visibility::Private, cpp);
writeHeaderAccessorMethodDecl(c, Uml::Visibility::Private, cpp);
writeOperations(c, true, Uml::Visibility::Private, cpp);
......@@ -1110,6 +1114,26 @@ void CppWriter::writeConstructorMethods(UMLClassifier * c, QTextStream &stream)
writeBlankLine(stream);
}
/**
* Write all datatypes for a given class.
* @param c the class for which we are generating code
* @param permitScope what type of method to write (by Scope)
* @param cpp the stream associated with the output file
*/
void CppWriter::writeDataTypes(UMLClassifier *c, Uml::Visibility::Enum permitScope, QTextStream &stream)
{
foreach (UMLObject* o, c->containedObjects()) {
if (o->visibility() != permitScope)
continue;
if (!o->isUMLDatatype())
continue;
UMLDatatype *d = o->asUMLDatatype();
if (d && d->isReference() && d->originType()) {
stream << indent() << "typedef " << d->originType()->name() << " " << d->name() << ";" << m_endl;
}
}
}
/**
* Replaces `string' with STRING_TYPENAME.
*/
......
......@@ -129,6 +129,7 @@ private:
void writeInitAttributeMethod(UMLClassifier * c, QTextStream &stream);
void writeInitAttributeDecl(UMLClassifier * c, QTextStream &stream);
void writeDataTypes(UMLClassifier *c, Uml::Visibility::Enum permitScope, QTextStream &stream);
QString umlObjectName(UMLObject *obj);
......
Supports Markdown
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