Project members: Inline code
With inline code members you are able to store within the project some snippets of native code (e.g. C). During code generation these code snippets are output together with other project members strictly according to the order in which the members are defined. Inline code members are represented in Composer by following bricks:
Typical application case is to use inline code to add C #include "..." directives to the generated code. In this manner you can combine the translated Chora platform-independent code with code to communicate with the target system.
Please note, an inline code member can exist only within a unit member. Moreover inline members are considered during code generation only. They have no effect during prototyping.
Add new inline code
★First switch to the Composer page for the respective unit member you want to add the new inline code member.
★Then, in the Gallery window, ensure that the folder Chora is opened.
★Look in the folder for the template named Inline Code.
★With the mouse, select the template and drag it into the Composer.
★Drop the template within the Composer.
Adding a new inline code member.
Name the inline code
★First ensure, that the inline code member is selected.
★Press the key F2 or select the menu item .
★Enter the new name in the Inspector window.
The name of the inline code member has no effect on the function of your application. However, it has to be unique within the unit the inline code member is defined inside.
Edit the content of the inline code
The content of inline code members is edited in the Code Editor window. For this purpose:
★First ensure, that the inline code member is selected.
★Press the key ENTER ...
★... or double click on the inline code member with the mouse.
Conditional compiling and inline code
By using the $if, $else, $elseif and $endif Chora conditional compilation directives, parts of the inline code, depending on the target platform, can be excluded. If the condition in an $if or $elseif directive is fulfilled, the following code part is taken over. If the condition is not fulfilled, the code is ignored. For example, the following C compiler #include directive is take over only when generating code for Microsoft Windows target:
$if $platform == Windows.*.* include <windows.h> $endif
Duplicate an existing inline code
You can create any number of copies of an already existing inline code member.
★First ensure, that the inline code member is selected.
★Press the keys CtrlC and CtrlV in succession ...
★... or hold the key Ctrl pressed while you drag and drop the selected inline code member.
★Finally rename the just duplicated inline code member.
Determine the position in the generated code
All members are generated strictly according to the order in which they are defined within the unit. The code generation starts always with the back most member (the member with the lowest order number). The actual order of an member can be inspected in the members area of the Inspector window. To change the code generation order you need to explicitly restack the member. For example, to arrange an inline code member at the top of the generated code, do following:
★First ensure, that the inline code member is selected.
★Press the keys CtrlShiftDown or select the menu item .
Control the code generation
With the attribute Generator you can selectively control, whether the inline code member is taken in account when generating code. Configuring this attribute with the value false will exclude the inline code member from your project.
Delete an inline code
★First ensure, that the inline code member is selected.
★Press the key DEL or select the menu item .
Attributes of an inline code
The following table shows the complete list of attributes provided by the inline code member:
Attribute name |
Short description |
---|---|
Determines the position and the size of a inline code member brick within the Composer window. |
|
Contains the description for the inline code member. |
|
Controls the code generation for the affected inline code member. |
Chora syntax of an inline code
This section describes the Chora syntax of how inline code members are stored inside Embedded Wizard project files. The knowledge about the syntax can be helpful when you plan to process the project contents by third party tools. In particular, the general purpose Export and Import functionality introduced in version 14 requires a good understanding of how project members are represented in Chora syntax to correctly interpret the exported members and synthesize the Chora code for members to import. Please note, Embedded Wizard project files (and thus Chora code) are encoded as text in UTF-8 format.
In Chora syntax, inline code members are always introduced with the keyword inline, followed by the name of the member and a its content (the native code) enclosed between a pair of curly braces {..}. Wherever necessary, the tokens are separated by whitespace signs.
The definition of an inline code member can be initiated by a comment block providing optional description for the member. The content of this comment corresponds to the value of the member's attribute Description. Furthermore the directives $rect and $output can be specified providing values for the corresponding attributes Brick and Generator. The following example demonstrates the described syntax:
// The inline code member ensures, that the both ANSI C #include \ // directives are taken over, as they are, into the generated code. // // $rect determines the position of the brick inside Composer window. // $output enforces this member to be taken in account during code \ // generation. $rect <10,10,210,50> $output true inline Includes { include <rtos_api.h> include <stdio.h> }
Each Chora file (or text exchanged with an external Export and/or Import tool) can be (or even should be) prefixed with $version directive. This directive determines the version number of the included Chora code. For details concerning the syntax of the version please see the chapter $version macro. Furthermore, the code can include a $scope directive followed by a path to a project member acting as the original owner of the corresponding code. That means the members described by the Chora code existed inside the member specified in $scope. In case of an inline code member, $scope would specify the name of the unit the member belongs to.