TOC PREV NEXT INDEX DOC LIST MASTER INDEX



Editing, Compiling, and Executing an Ada Program (Apex/Summit)

This module guides you through the steps needed to create, edit, compile, and run a simple Ada procedure. All Apex components (code, documentation, etc) must be in subsystems and views.

This module has the following topics. To move to the first topic, click on it or click on the Next button.

Prerequisites for this Module

Topics in this Module

Average Time to Complete this Module

45 minutes.


Creating Subsystems and Ada Views

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.

Every subsystem is associated with a set of views. Working views provide areas for the development and integration of software. Release views contain the products developed within a subsystem during the development process.

The average time to complete this module is 10 minutes, but your rate of speed will depend on how many side trips you take.

Note: In UNIX, a subsystem is a directory with a .ss filename extension and a view is a subdirectory with a .wrk or .rel extension. Because subsystems and views are directories in UNIX, their names are case-sensitive. In the following exercises, you can use whatever directory names you want for parent directories, but use the subsystem and view names that are provided, typed in all-lowercase letters.


Creating a Subsystem

In this exercise, you will create a subsystem named project1.ss. If you have already created this subsystem, open a viewer with this subsystem and skip to the Creating an Ada View topic.

1. . Open a directory-viewer window.

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 .ss extension is added for you automatically. For this exercise, use $HOME/project1.

5. . With the Place storage in subsystem's enclosing directory and the Visit the new subsystem check boxes selected the default settings), close the New Subsystem dialog box by clicking the OK button.

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.


Creating an Ada View

In this exercise, you will create a working view named hello.wrk. The hello.wrk view will be nested in the project1.ss subsystem you created in the previous exercise.

1. . Select the New command from the File menu in the project1.ss directory-viewer window. Apex opens a cascading menu.

2. . Choose the New View menu item from the New submenu. Apex displays the New View dialog box:

3. . In the Name field, type the view name hello.

4. . Keep the View Type set to Working and the Language set to Ada95.

5. . If Apex is correctly installed, the text in the Host Architecture and Model fields match the characteristics of your workstation. Leave this field at its default setting.

6. . Leave the Visit the new view check box selected, its default setting.

7. . Leave all the other options in the New View dialog box set to their default settings.

8. . With the Place storage in subsystem's enclosing directory and the Visit the new view check boxes selected the default settings), close the New View dialog box by clicking the OK button.

The Jobs window displays the view being created.

When the New View dialog box is executed with the Visit the new view check box selected, Apex opens a directory-viewer window showing you that a working view named hello.wrk has been created in the project1.ss subsystem.

9. . Choose the Close command from the File menu in the project1.ss directory-viewer window because you are going to be using the directory-viewer window from now on.

The Online Reference contains additional information on the contents of an empty view.


Creating an Ada Procedure

Perform the following steps from the directory viewer displaying the working view (project1.ss/hello.wrk 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 $HOME/project1.ss/hello.wrk as the Filename.

1. . Select the New command from the File menu in the hello.wrk 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 hello.wrk view 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. . With the Visit it check box selected, execute the New Ada dialog box by clicking the OK button.

When you complete step five, 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 Procedure

The 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 project1.ss/hello.wrk view, you will see that hello.wrk 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:

There are many editor key bindings.

The display area of the Ada editor window for hello.2.ada 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):

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:

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 Procedure

As you use different Apex commands to compile the Ada procedure, you progress the unit through different compilation states. The compilation states are listed below:
Compilation State
Description
Associated Command
Source
The object has been parsed. Not supported currently for C/C++
Compile > Syntax
Installed
The object has been checked for semantic accuracy. Not supported currently for C/C++.
Compile > Analyze
Coded
Object code has been generated for the object.
Compile > Code
Linked
An executable has been generated for the object.
Compile > Link
Unparsed
The source file has been updated since the compiler was last run
Compile > Parse

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:

2. . Select Compile > Semanticize.

This command checks the code in this object for semantic errors.

The Message window displays this message:

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:

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 project1.ss/hello.wrk 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 view hello.wrk 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.

The Job window displays the execute job.

The Output window prints Hello, Apex!


Modifying the Ada Procedure

Now 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:

2. . Type:

3. . Position the cursor at the start of the Put_Line statement:

4. . Type:

5. . Select Compile > Syntax (also found on the button bar).

This completes the syntax of the if statement to look like this:

6. . Change the Put_Line statement to be:

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:

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 project1.ss/hello.wrk 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.

The Output window prints the message.

You have just created and executed Ada program.

Close all the windows you have created during this module.


Rational Software Corporation 
http://www.rational.com
support@rational.com
techpubs@rational.com
Copyright © 1993-2001, Rational Software Corporation. All rights reserved.
TOC PREV NEXT INDEX DOC LIST MASTER INDEX TECHNOTES APEX TIPS