Introduction

Cxx is a rich and complex language. Although it has been standardized by the ISO, its syntax and grammar remain very flexible, thereby allowing several different styles and variants in the code. Of course, these characteristics make it more complex to write Cxx parsers and Cxx reverse, with perfect parser reliability remaining a virtually impossible-to-reach goal. Even well-known Cxx compilers introduce specificities and limitations of their own.This is also true for the Modelio Cxx Reverser reverse tool.

Furthermore, the problem of reversing code to produce an equivalent UML model can encounter an additional difficulty, since Cxx supports certain constructions that cannot easily be mapped to UML syntax, due to a lack of direct equivalence in UML.

To make the most of the Modelio Cxx Reverser reverse tool, it is worth following some best practice tips. The following ten tips should help you improve the quality of your reversed model. Experience has proved that by taking these small precautions, you can reap significant benefits in the reversed model.

Divide your sources

Reverse operations can be very time-consuming. Due to system resources, it can be a good idea to divide application sources into separate subsystems, before reversing them one by one.

Between every reverse, save the project. This will force the use of the Modelio garbage collector, thus freeing up memory, which can improve reverse speed.

Last but not least, reversing smaller parts greatly facilitates the diagnosis of potential problems.

Respect dependencies between subsystems

When reversing a large application subsystem by subsystem (as described in the previous paragraph), dependencies between the different subsystems must be respected. In the subsystem dependency graph, subsystems that depend on no other subsystems should be reversed first, followed by subsystems depending only on them and so on. This process minimizes the number of partially instantiated objects, and reduces the risk of post-reverse object re- identification.

Look into your makefile to find specific options

In most applications, several parameters, mainly macro definitions and include paths, are passed to the compiler. These options have an influence on the code that is truly compiled.

This "on the fly code transformation" is carried out by the C preprocessor. The Modelio Cxx Reverser reverse tool can manage these options in the same way as a preprocessor, which means that passing the right parameters is a key to success.  A good and pragmatic approach is to examine the options used when the application is compiled, for example, by looking at the makefile (or equivalent build file).

Reverse libraries and implementations differently

Reversing a complete application and reversing a compiled library are two different things.

In the case of reversing an application, the most important files are usually implementation files (*.cpp) . All the necessary header files are included in the implementation files, and only the implementation files themselves have to be selected in the "Cxx Reverse" window.

For the reverse of a tier library, only header files should be selected. This will provide a structural UML model without Cxx implementation notes that should be sufficient. Furthermore, in the case of tier libraries, implementation files are most often unavailable.

Use empty macros for specific keywords not implemented

Some compilers use specific keywords.  For example, Microsoft Visual Cxx defines additional keywords such as "cdecl" or "stdcall".  These additional keywords are not known by the Modelio Cxx Reverser reverse tool parser, as it conforms to the ANSI norm and not to the Microsoft variant.

In this situation, the best thing to do is to ignore these useless keywords, by providing them as an empty macro using the configuration interface.

Use exclusions to limit model size

A complete model can be very large, but a complete model is not always needed! Using reverse options, the reverse can be limited to only the core of your application, without including, for example, technical libraries. This means you can concentrate only on the business part of the model. Identifying and defining the parts of the application that are not to be reversed (in the second window of the reverse wizard) greatly helps keep the model within manageable limits in terms of its size.

Save extensions in extension files to re-use them

The Cxx reverse tool provides a set of extensions for some XML file compilers. Where several applications use the same specific extensions, it is recommended that these extensions be added to the configuration file for re-use.

The more standard the code, the better the reverse

The best reverse is achieved from the most standard code. The Modelio Cxx Reverser reverse tool has been carefully designed to make the best use of the STL library. The use of STL containers gives the reverse tool the ability to rebuild correct associations.Non-standard constructs, although accepted by your compiler, can fool the Modelio Cxx Reverser reverse tool parser and lead to poor results.

Work on your code again, in order to better reverse it

Sometimes simple modifications in the application code can significantly improve the quality of the model. For example, replacing a typedef by its expansion in its uses, or rewriting the declaration of an association can lead to a considerable enhancement of the model.

Where parsing errors occur, concentrate on the first error

The Cxx language has state-full and irregular grammar. This means that a notion of state exists in every statement in a file. When the parser finds an error, it can be confused about the current state and report false errors. Thus, in the list of errors, always look at the first one and correct it, since subsequent errors can, in fact, be false negatives.