Code generation for files

During code generation, files produce full production code, including behavioral code. In terms of their modeling properties, modeled files are like implicit singleton objects.

For an active or a reactive file, IBM® Rational® Rhapsody® generates a public, implicit object (singleton) that uses the active or reactive functionality. The name of the singleton is the name of the file.

Note: The singleton instance is defined in the implementation source file, not in the package source file.
For a variable with a Constant modifier, Rhapsody generates a #define 
statement. For example:

    #define MAX 66

The following table shows the differences between code generation of an object and a file.

Table 1. Differences between code generation of an object and a file
Model element File code Object code
Data member (attribute, association, or object) A global variable A member in the singleton struct
Function nameYou can configure the name pattern for functions (for files, objects, and other elements) using the <lang>_CG::Operation::PublicName and <lang>_CG::Operation::PrivateName properties. The function name pattern is <Function>. The name pattern for public functions is <Singleton>_<function>.

The pattern for private functions is <Function>.

Function signature The me argument is generated when required to comply with the signature of framework callback functions (for reactive behavior). The same.
Initialization Variables and associations are initialized directly in the definition. For example:

int x=5;

Objects are initialized in a generated Init function.

Done in the initialize function.
Type name The name pattern for types (regardless of visibility) is <Type>. The name pattern for public types is <Singleton>_type.

The name pattern for private functions is <Type>.

The name pattern can be configured using the <lang>_CG::Type::PublicName and PrivateName properties.

Visibility Public members are declared as extern in the specification (.h) file and defined in the implementation (.c) file.

For example:

extern int volume;

Private members are declared and defined in the implementation file as static.

For example:

static int volume;

Member visibility is ignored; the visibility is a result of the visibility of the struct.

For example:

struct Ob_t {
int volume;
};

Auto-generated
Initialization and cleanup Only algorithmic initialization is done in the initialization method (creating parts; initializing links, behavior, and animation).

The initialization and cleanup methods are created only when needed.

The name of the initialization function is <file>_Init; the cleanup function is <file>_Cleanup.

Any initialization is done in the Init method.

Init and Cleanup methods are generated by default.

Framework data members Rational Rhapsody generates a designated struct that holds only the framework members, and a single instance of the struct named <file>. The struct name is <file>_t.

For example:

struct Motor_t {
RiCReactive ric_reactive;
}

Framework members are generated as part of the object struct declaration.
Call framework operations Framework operations on the file are called using the file.

For example:

CGEN(Motor, ev());

Framework operations on the singleton are called passing the singleton instance.

For example:

CGEN(Motor,ev());

Statechart data members Statechart data members are generated as attributes of the generated structure.

For example:

struct F_t {
...
enum F_Enum {
F_RiCNonState=0,
F_ready=1}
F_EnumVar;
int rootState_subState;
int rootState_active;
};

Statechart data members are generated as part of the struct.
Statechart function names Public statechart functions are generated using the prefix <file>_.

For example:

myFile_sIN()

Use the same naming convention as any other operation.

You can configure the name pattern for functions (for files, objects, and other elements) using the <lang>_CG::Operation::PublicName and PrivateName properties.


Feedback