Page 1 of 2

Module Diagram for C

PostPosted: Tue 12 Nov 2013 10:34
by hboehmer
Hello Bruno,

I'm an engineer in the field of embedded systems. I think BOUML is great for support system development because of the ability to generate code direct from a class diagram. But it's necessary to have a compiler for C++. For a large amount of microcontroller families there are only C-Compilers avaliable.

When developing a small embedded system on step is to construct a module diagram. This is very similar to a class diagram. A module is like a class in common only with operations but without attributes. The code generated from a module should also be an implementation file and an declaration file (with the function prototypes).

The only association between modules is a directional dependency. When generating code this leads to an include statement in the implementation file of the module which depends on an other module.

Sometimes a module have also some attributes (global variables). They need to be defined in the implementation file when code generating. In the header file they needs a declaration with the keyword 'extern'.

I have tried to use the class diagram of BOUML to design a module diagram. I deleted the definition '${class}::' in the operation dialog for every operation on the tab 'C++'. Also I deleted some definitions in the class dialog (except '${members}'). So when generating code I get implementation files with only keywords my c-compiler understand. I have only to rename the files from *.cpp to *.c. But in the header file I can't suppress the keywords public, private, etc. For the global variables I also don't have a solution.

Can you imagine to support the language C with BOUML in the future?

Best regards,
Heiko Boehmer

Re: Module Diagram for C

PostPosted: Thu 14 Nov 2013 17:00
by Bruno Pagès
Hello,

To use a struct rather than a class allows to not generate public, but this solve only a part of the problem.

To support C means to have the code generator, reverse and roundtrip, but this have sense in UML only if the C code respect rules like your 'module', so is not 'standard' C. To have only a 'patched' version of the C++ code generator to be compatible with your request is not difficult to do but is only a partial answer.

Re: Module Diagram for C

PostPosted: Wed 20 Nov 2013 06:59
by hboehmer
Hello Bruno,

thanks for your answer. I understand that support for a new language is a very complex task. Especially for a language like C without direct support for object oriented concepts like classes.

The hint to stereotyp <<struct>> is a possible workaround. But it's for a C programmer a little bit confusing because in C this keyword don't allows to contain operations i.e. functions.

So I thought, perhaps there is a possibilty to add a new stereotyp <<module>> with the same functionality like <<struct>>.

In the generation settings of BOUML on the second tab 'Stereotype' there is a list with 'Classes stereotypes correspondence'. I added at the end of this list a new line with the keyword 'module' in the first column 'UML'. All other columns I set to 'struct'.

But if I choose the new stereotype <<module>> in the class dialog the generated source code will have again the keyword 'public'.

Is there an other way to add a new stereotype? Or is it not possible?

Best regards,
Heiko Boehmer

Re: Module Diagram for C

PostPosted: Wed 20 Nov 2013 08:59
by Bruno Pagès
hboehmer wrote:But if I choose the new stereotype <<module>> in the class dialog the generated source code will have again the keyword 'public'.

At class level <<module>> is well managed as <<struct>>, but yes this is not the case at attribute/operation level, this is a bug, I will fix that.

Yes to fully add a new language is a huge work, I will not add C like that. Except for the generation settings the editions will use the C++ tab of the editors. The code generation will be done by a dedicated C generator, this is necessary because struct/union/enum must be managed but their use is not the same in C and C++, for instance if S is a struct the C++ form "S s" is invalid and must be "struct S s" in C. I don't plan to add C reverse nor roundtrip.

<<module>> is a new 'builtin' stereotype, applicable on classes, managed by the C generator. It is necessary to add this stereotype even there is a dedicated generator to get the right default definition and code generation preview during the editions.

a class stereotyped <<module>> generate nothing for itself, only its members are generated.
in a class stereotyped <<module>> a non static attribute or relation to an other class produces a global variable in the source file, and its declaration as extern in the header file.
in a class stereotyped <<module>> a static attribute or relation to an other class produces a static variable in the source file, nothing in header file
in a class stereotyped <<module>> a non static operation produces a C function in the source file, and its declaration as extern in the header file
in a class stereotyped <<module>> a static operation produces a static C function in the source file, nothing in header file

classes stereotyped struct/union/enum produce expected code in header files.

Re: Module Diagram for C

PostPosted: Fri 22 Nov 2013 07:17
by hboehmer
Hello Bruno,

thanks for your answer. This sounds all very good. I'm curious about the next Version of BOUML.

Best regards,
Heiko Boehmer

Re: Module Diagram for C

PostPosted: Sun 24 Nov 2013 11:59
by Bruno Pagès
Bruno Pagès wrote:At class level <<module>> is well managed as <<struct>>, but yes this is not the case at attribute/operation level, this is a bug, I will fix that.

I was wrong, there is no bug, the visibility is not generated when it is 'public'

Re: Module Diagram for C

PostPosted: Fri 7 Feb 2014 07:15
by Bruno Pagès
Hello Heiko,

First sorry for the very long delay between your request and its realization in Bouml.

Please, are you interested to test the new version of Bouml including the C generation before I deliver it officially ?

Best regards,
Bruno pagès

Re: Module Diagram for C

PostPosted: Sat 1 Mar 2014 16:24
by Bruno Pagès
Hello,

Feature available in Bouml 6.5, please refer to the documentation chapter C generator

Best regards,
Bruno Pagès

Re: Module Diagram for C

PostPosted: Fri 14 Mar 2014 12:28
by hboehmer
Hello Bruno,

thanks for the features concerning C. I have made some first successful tests.

A problem exist if someone forget to load the file C:\Program Files\Bouml\C\C.prj before creating a new project.
Consider the following situation:
Starting BOUML,
Project\New,
Languages\C managment and default...,
New class view,
New class, insert stereotype <<c_module>> in class dialog,
Add operation, then the Operation dialog hangs and can't be closed.

I think the problem is, when I choose the language C, the stereotype <<c_module>> is not in the Generation settings dialog.

Best regards,
Heiko Boehmer

Re: Module Diagram for C

PostPosted: Fri 14 Mar 2014 13:38
by Bruno Pagès
Hello,

I did your sequence and I am able to add operations without problems

you say "dialog hangs and can't be closed", do you mean bouml is dead/frozen ?

what it the name of the operation and which fields you set in the operation dialog ?