Prev Next

Language Macros

When reverse engineering a language such as C++, you might find preprocessor directives scattered throughout the code. This can make code management easier, but can hamper parsing of the underlying C++ language.

To help remedy this, you can include any number of macro definitions, which are ignored during the parsing phase of the reverse engineering. It is still preferable, if you have the facility, to preprocess the code using the appropriate compiler first; this way, complex macro definitions and defines are expanded out and can be readily parsed. If you don't have this facility, then this option provides a convenient substitute.

Access

Ribbon

Configure > Reference Data > Settings > Preprocessor Macros   or

Code > Configure > Options > Define Preprocessor Macros

Define a macro

Step

Action

See also

1

Select the 'Preprocessor Macros' menu option.

The 'Language Macros' dialog displays.

2

Click on the Add New button.

3

Enter details for your macro.

4

Click on the OK button.

Macros Embedded Within Declarations

Macros are sometimes used within the declaration of Classes and operations, as in these examples:

     class __declspec Foo

     {

     int __declspec Bar(int p);

     };

If declspec is defined as a C++ macro, as outlined, the imported Class and operation contain a Tagged Value called DeclMacro1 with value __declspec (subsequent macros would be defined as DeclMacro2, DeclMacro3 and so on).

During forward engineering, these Tagged Values are used to regenerate the macros in code.

Define Complex Macros

It is sometimes useful to define rules for complex macros that can span multiple lines; Enterprise Architect ignores the entire code section defined by the rule.

Such macros can be defined in Enterprise Architect as in these two examples; both types can be combined in one definition.

Block Macros

     BEGIN_INTERFACE_PART ^ END_INTERFACE_PART

The ^ symbol represents the body of the macro - this enables skipping from one macro to another; the spaces surrounding the ^ symbol are required.

Function Macros

     RTTI_EMULATION()

Enterprise Architect skips over the token including everything inside the parentheses.

Notes

  • You can transport these language macro (or preprocessor macro) definitions between models, using the 'Configure > Model > Transfer > Export Reference Data' and 'Import Reference Data' options; the macros are exported as a Macro List

Learn more