![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Editing, Compiling, and Executing an Ada Program (Apex/ClearCase) This module guides you through the steps needed to create, edit, compile, and run a simple Ada procedure using Baseline ClearCase. For an example of how to create a program using UCM, see please see the chapter on Developing a Program using ClearCase in Getting Started. All Apex code components must be in Rational subsystems to be compiled.
Prerequisites for this Module
- Bringing Up Apex
- Created and Activated VOB
Topics in this Module
- VOBs and Subsystems
- Creating a Subsystem
- Creating an Ada Procedure
- Editing the Ada Procedure
- Compiling and Linking the Ada Procedure
- Executing the Ada Procedure
- Modifying the Ada Procedure
Average Time to Complete this Module
VOBs and SubsystemsWhen using Apex/ClearCase, you must use ClearCase repositories (VOB(s) and ClearCase views) for your Rational subsystems. If your adminstrator does not have a VOB and ClearCase view set up for you to use for this tutoriarl, please see the instructions in the chapter on Developing a Program using ClearCase in Getting Started. This example uses a VOB with a path of /vobs/test.
Apex supports the dividing of a software-development effort into high-level components called subsystems, each containing a group of logically related objects. Subsystems let you group related files, ada packages and other compilation units together, hiding those that contain only implementation details.
Note: In UNIX, a Rational subsystem is a directory with a .rss filename extension.
Models
One important characteristic of a Rational subsystem is its model. A model is a Rational subsystem that serves as a prototype for another Rational subsystem. The model provides a base structure of subdirectories, policies (compiler options, target keys, etc., by way of switches), and a base set of Imports.
Creating a SubsystemIn this exercise, you will create a subsystem named test.rss.
- 1. . Open a directory-viewer window of your VOB (/vob/test) if one is not opened.
- 2. . Choose the New command from the File menu. Apex displays a cascading menu.
- 3. . Choose the New Subsystem menu item from the New submenu. Apex displays the New Subsystem dialog box:
![]()
- 4. . Enter the full pathname of the subsystem you wish to create in the Subsystem Full Name field. The .rss extension is added for you automatically. For this exercise, use /vobs/test/test.
- 5. . Because we will be creating an Ada program, the Language default should be Ada. Verify the Host Architecture matches the architecture of the machine on which you are running.
- 6. . Make sure the Visit the new subsystem check box is selected.
- 7. . Select the Make it an element option so that this Rational subsystem will be controlled. Any element that is controlled needs the enclosing Rational subsystem to be controlled. If you do not control it now, it will need to be controlled when you control the first element in this Rational subsystem. When you select this option, a Note field will be displayed. Enter a Note to be associated with controlling this element.
To create your new Rational subsystem, click OK or Apply. When the dialog box closes with the Visit the new subsystem check box selected, Apex opens a directory-viewer window showing you the subsystem that was created.
See File > New for more information. Getting Started contains additional information on the contents of an empty Rational subsystem.
Creating an Ada ProcedurePerform the following steps from the directory viewer displaying the working view (test.rss should be the first line in the directory viewer) you created in the previous topic. If you do not have it displayed, execute the File > Open command and enter /vobs/test/test.rss as the Filename.
- 1. . Select the New command from the File menu in the test.rss directory-viewer window. Apex opens a cascading menu.
- 2. . Choose the New Ada menu item from the New submenu. Apex displays the New Ada dialog box. Notice that the pathname of the test.rss subsystem appears in the Context field.
- 3. . Change the settings of the buttons labeled Create an empty Ada from Package and Spec to Procedure and Body, as shown below:
![]()
- 4. . Enter the name hello in the Name field as shown in the preceding illustration. hello will be the simple name of the Ada unit you are creating. It is not necessary to add any filename extensions. As you develop the hello application, Apex will create and use filenames based on the simple name hello, as appropriate.
- 5. . To have Apex open an editing window for your new source file as soon as the file is created, check the Visit it check box.
- 6. . If you want your procedure to be controlled under ClearCase, check the Make it an element check box. This will make the enclosing Rational subsystem, /vobs/test/test.rss, also aVOB element in ClearCase.
- 7. . Make sure the Visit it check box is checked. If Visit it is not checked, Apex will not display your new source file in a window when it is created.
When you complete step seven, Apex creates an Ada procedure named hello.2.ada and displays the procedure's source code in an Ada editor window. The empty file contents is defined by the corresponding template file:
![]()
Editing the Ada ProcedureThe Ada Editor Window
The Ada editor window is where you write, edit, compile, and link code. As the preceding illustration shows, the hello.2.ada window created by Apex contains a comment line identifying the file, along with a stub that is ready for you to fill in.
If you open a directory-viewer window that lists the contents of the test.rss subsystem, you will see that it now contains the hello.2.ada source file:
![]()
If you were to create other files for the hello application, Apex will automatically give all related bodies the filename extension .2.ada and related specifications the filename extension .1.ada. Apex creates and applies these extensions automatically when you create the file.
The Online Reference contains more information on the File > New command.
Basic tips for using the editor
- To type new text, move the blinking cursor to the exact insertion point where you want to enter text. You can use the arrow keys to move the cursor, or you can click the mouse pointer on the space you want the cursor to appear.
- The editor window is always in insert mode; unlike other line editors (vi, for example) you can type and move the cursor without toggling the command mode.
- To delete the previous character, use the Delete or Back Space keys.
There are many editor key bindings.
The correct version of the hello.2.ada in the Ada editor window looks like this:
![]()
To create the procedure body, follow these steps:
- 1. . Use the Ada editor window containing the hello.2.ada file, which you created in the previous exercise.
- 2. . Select the word statement and the brackets around it, as shown in the above example. (You can select text in the editor window either by clicking and dragging the mouse or by moving the insertion point backward or forward with the View > Prompt -> menu item or the View > Prompt <- menu item.)
- 3. . Replace the word statement and the brackets around it with the following text (notice that as soon as you start typing, the text you are replacing disappears):
putline ("Hello, Apex!
Note: The errors in the above line are placed there on purpose; putline should be put_line, and the ( and " delimiters should be members of matched pairs. These errors will be corrected later in this module.
- 4. . Position the cursor before the procedure statement, as follows:
![]()
- 5. . Insert this text before the words procedure Hello is:
with text_io; use text_io;
Note: Again, do not worry about errors or missing text. That will be fixed later in this module.
You can see an example of how hello.2.ada looks at this point.
Compiling and Linking the Ada ProcedureAs you use different Apex commands to compile the Ada procedure, you progress the unit through different compilation states. The compilation states are listed below:
If you skip one or more compilation steps, Apex performs the intermediate steps needed to reach the compilation state associated with the command. For the purpose of this exercise, you will take each step in turn.
- 1. . Select Compile > Syntax. This command parses the object and performs the following operations on the format of the code:
- Pretty-prints the code (adds indentation and standardizes capitalization).
- Adds missing closing identifiers (such as semicolons and parentheses).
- Saves the contents of the Ada editor. This is true for all of the Compile menu commands shown in the table above.
- 2. . Select Compile > Semanticize.
This command checks the code in this object for semantic errors.
The Message window displays this message:
*** Unit has semantic errors
In the language editor, Putline is called out.
Use Compile > Semanticize regularly as you develop an object. It is a quick way to find semantic errors and correct them. Once you have corrected the errors, you can use Compile > Analyze to install the object.
- 3. . Correct the error in the code. The corrected line should look like this:
Put_Line ("Hello, Apex!");
You can see how hello.2.ada should look now.
Note: You do not need to worry about capitalization except in strings. It is corrected by Apex's pretty printing.
- 4. . Select Compile > Analyze.
This command checks the code for semantic errors and advances the unit to the installed state.
The Jobs window displays the analyze job.
The Message window displays a log of the command.
- 5. . Select Compile > Code.
This command generates object code for the object.
The Jobs window displays the code job.
The Message window displays a log of the command. The object is promoted to the coded compilation state.
Use Compile > Code regularly as you develop an object. It is a quick way to find errors and correct them. Once you have corrected the errors, you can use Compile > Link to code the object.
- 6. . Select Compile > Link to create an executable.
The Jobs window displays the link job.
The Message window displays a log of the command. The unit is promoted to the linked state.
The executable is displayed in the test.rss directory viewer in the form hello*.
As mentioned before, if you skip one or more compilation steps, Apex performs the intermediate steps needed to reach the compilation state associated with the command. If you have made changes to the object since the last compilation step, Apex automatically saves the changes as part of the operation.
Executing the Ada Procedure
- 1. . Select the executable in the directory viewer (click on it with the mouse pointer).
If the directory viewer displaying the subsystem test.rss is covered, you can raise it by selecting Navigate > Context in the language editor.
- 2. . Select File > Run to display the Run dialog box.
- 3. . Click on OK to execute the procedure.
Modifying the Ada ProcedureNow that you have the basic hello program working, you will expand this procedure by adding an if statement. The resulting change causes the program to print out one message if executed on the first day of the month, and a different message if executed on any other day.
- 1. . In the hello.2.ada language editor window, position the cursor at the end of this line:
use Text_Io;
- 2. . Type:
with calendar; use calendar
- 3. . Position the cursor at the start of the Put_Line statement:
Put_Line ("Hello, Apex!");
- 4. . Type:
if Day (Clock)=1
- 5. . Select Compile > Syntax (also found on the button bar).
This completes the syntax of the if statement to look like this:
if Day (Clock) = 1 then Put_line ("Hello, Apex!"); else [statement] end if;
- 6. . Change the Put_Line statement to be:
Put_Line ("Hello, first day of the month.")
- 7. . Select the Put_Line statement by triple-clicking on the line.
- 8. . Select Edit > Copy.
- 9. . Select [statement] by clicking on the word statement.
- 10. . Select Edit > Paste.
The Put_Line statement is duplicated.
- 11. . Change the second Put_Line statement to be:
Put_Line ("Hello, rest of the month.")
- 12. . Select Compile > Syntax.
Your new changes are formatted and checked for syntax errors.
The following steps are optional. Use them if you want to execute the modified program.
- 13. . Select Compile > Link.
- 14. . When the unit is linked, go to the test.rss directory viewer and click on hello* to select it.
- 15. . Select File > Run to display the Run dialog box.
- 16. . Click on OK to execute the procedure.
You have just created and executed Ada program.
Rational Software Corporation http://www.rational.com support@rational.com techpubs@rational.com Copyright © 1993-2001, Rational Software Corporation. All rights reserved. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |