![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Developing a Program Using Apex/Summit Programs written in Ada and/or C/C++ often contain many objects. An Ada and/or C/C++ application typically consists of many interdependent units. Apex is designed to support the development of large, complex systems. Most systems are decomposed, or divided, into subsystems to make them more manageable. Criteria for decomposing systems into subsystems are described in the Concepts Guide.
Apex performs all compilation in the context of subsystems, regardless of program size. This chapter shows how to develop a simple program in a single subsystem.
A view is a concrete version of a subsystem. A view contains the files that represent the logical objects in a subsystem. Because views contain actual files, they are directories in which compilation is performed.
Note: The screen captures on your system may appear slightly different than those in this document. Some menus and dialog box fields depend on which options and/or layered products are installed.
About This ChapterThis chapter describes subsystems and views and shows how to use them to create and develop programs. For a quick, simple introduction to Apex, this chapter covers how to create an Ada or a C++ program. A simple "hello world" program is created using the steps in Figure 12.
Figure 12 Steps in Creating a Simple Program
![]()
The topics covered in this chapter are:
- Introducing the Directory-Viewer Window
- Creating a Summit/CM Subsystem
- Creating a Summit/CM View
- Creating an Ada Unit
- Creating a C++ File
- Using the Apex Editors
- Compiling and Linking a Program
- Executing a Program
Note: The type of program you can create is dependent on which variant of Apex you are using. If you are using Rational Apex Ada, follow the instructions to create the Ada program. If you are using Rational Apex C/C++, follow the instructions to create a C/C++ program. If you are using Rational Apex Duo, you can do either.
Another easy way to become familiar with subsystems and directories is to work through the exercises in the online tutorial, Tutorial which is started by the Help > Tutorial command.
Note: The general discussions of subsystems, views and the development process in this chapter are applicable to both native and embedded/cross Apex systems. However, due to the inherent complexity of embedded systems, there are additional steps that must be taken to use Apex cross products. These are discussed in detail in "Getting Started" in the following documents:
Introducing the Directory-Viewer WindowTo help you set up, access, and manage the files and directories in which program files are stored, Apex provides a special kind of window called a directory-viewer window.
When a directory is visited or opened, Apex opens a directory-viewer window that displays a list of files and directories. You can use the directory-viewer window to navigate through the UNIX directory structure, open files and directories, and view other files and directories.
There are two ways to view an object listed in the directory-viewer window. You can select the object's name and click Visit, or you can double-click the object's name.
You can also issue commands from the directory-viewer window's File menu to load, save, and print files and to execute and debug programs.
For example, if you visit your home directory from the Apex panel, Apex displays a directory-viewer window such as the one illustrated in Figure 13.
Figure 13 Directory-Viewer Window
![]()
For more information about the directory-viewer window and how to use it, see Using and Customizing the Apex GUI.
Creating a Summit/CM SubsystemCompilation must be performed in a subsystem. You can create a Summit/CM subsystem anywhere in a UNIX directory system except in another subsystem —— subject, of course, to normal UNIX permission restrictions.
You can create subsystems for personal use or for use in a group project. Generally, when you create a subsystem for personal use, you place it in a directory that is convenient for you to use, such as your home directory. When you create a subsystem for a group project, it should be placed in a common area accessible by all members of the group.
To compile and run the hello.2.ada or hello.C program mentioned in the preceding section, you need to create a subsystem. The subsystem created for the hello.2.ada or hello.C program in the Tutorial is named project1.ss.
To create the project1.ss subsystem:
- 1 . Select the File > New > New Subsystem menu item.
Apex then opens the New Subsystem dialog box illustrated in Figure 14.
Figure 14 New Subsystem Dialog Box
![]()
- 2 . Enter the full pathname for the new subsystem in the text field labeled Subsystem Full Name.
The pathname must be a fully qualified pathname (a pathname that starts with /). It is not necessary to enter the .ss extension in the text field; Apex adds that extension automatically. For this example, we are using /apex/project1.
- 3 . Make sure the Visit the new subsystem check box is selected.
- 4 . To create your new subsystem, click OK or Apply.
Creating a Summit/CM ViewA Summit/CM view is an object within a subsystem that contains the actual files with the program source.
Models
One important characteristic of a view is its model. A model is a view that serves as a prototype for another view. The model view provides a base structure of subdirectories, policies (compiler options, target keys, etc., by way of switches), and a base set of Imports. For Ada, a model provides a package standard and built-in Ada packages, such as Text_Io.2.ada. For C/C++, a model provides access to the standard C library. Apex provides a default model for programs that are compiled and run using the same platform architecture that Apex uses. Models are described in detail in Programming with Apex.
Types of Views
There are two kinds of views: working views, in which active development is performed, and release views, which stores frozen release views of a subsystem.
Creating a View Step by Step
To create a working view for the hello.2.ada or hello.C program, follow these steps:
- 1 . Click the File > New > New View menu item from the directory-view of project1.ss.
Apex opens the New View dialog box illustrated in Figure 15.
Figure 15 New View Dialog Box
![]()
- 2 . Enter a name for your new view in the Name text field. It is not necessary to enter a filename suffix in the Name text field. Apex automatically adds a .wrk suffix for a working view or a .rel suffix for a release view. Since we are creating a working view, leave the view type as Working. For this example, we are using the name hello.wrk.
Make sure that the name of the appropriate subsystem is in the Subsystem field.
- 3 . To specify a model for your view, enter a name for the model in the Model text field. A default model which is determined by the values in the View Type and Host Architecture fields should already be displayed.
If you wish to use a different model, select the Navigator icon next to the Model field. The Model Selection dialog box is displayed. You can also either change the value of the View Type or Host Architecture field, or click the Alternatives Icon and select a model from the resulting pop-up menu.
For more information about the Model option, see Models.
- 4 . To have Apex open a directory-viewer window of the new view you are creating, check the Visit it check box.
- 5 . To create your new view, click OK or Apply.
Creating an Ada UnitIn Apex, the names of Ada source files follow a specific naming convention. The specification of a source file is always the name of the unit with the suffix .1.ada added. Similarly, the body of a source file is always the name of the unit with the suffix .2.ada added.
- 1 . Select the File > New > New Ada menu item.
Apex opens the New Ada dialog box.
- 2 . Reset the option buttons labeled Package and Spec to read Procedure and Body.
- 3 . Enter a name for the procedure you are creating in the Name text field.
It is not necessary to append the suffix .2.ada (the conventional suffix for an Ada procedure) to the filename you enter. Apex automatically does this.
- 4 . 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.
- 5 . If you want your procedure to be controlled under the Rational Summit/CM system, check the Make it controlled check box. The Summit/CM system is described in Using and Customizing Summit/CM
.- 6 . 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.
- 7 . Click OK or Apply.
This dialog box with the appropriate settings is shown in Figure 16.
Figure 16 New Ada Dialog Box
![]()
The file is created using the appropriate template file which defined the initial contents of this type of file.
Apex then opens an Ada editor window for your new source file as illustrated in Figure 17.
Figure 17 Ada Editor Window
![]()
Creating a C++ FileIn Apex, the names of C/C++ source files follow a specific naming convention. C/C++ header files have the suffix .h. C++ source files have the suffix .C and C source files have the suffix .c.
- 1 . Select the File > New > New C++ menu item.
Apex opens the New C++ dialog box.
- 2 . Reset the option buttons labeled Class and Header to read Main and Implementation.
- 3 . Enter a name for the function and for the filename you are creating in the Name and Filename text fields.
It is not necessary to append the suffix .C (the conventional suffix for a C++ function) to the filename you enter. Apex automatically does this.
- 4 . 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.
- 5 . If you want your procedure to be controlled under the Rational Summit/CM system, check the Make it controlled check box. The Summit/CM system is described in Using and Customizing Summit/CM
.- 6 . 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.
- 7 . Click OK or Apply.
This dialog box with the appropriate settings is shown in Figure 18.
Figure 18 New C++ Dialog Box
![]()
The file is created using the appropriate template file which defined the initial contents of this type of file.
Apex then opens a C/C++ editor window for your new source file as illustrated in Figure 19.
Figure 19 C/C++ Editor Window
![]()
Using the Apex EditorsThe Apex Ada and C/C++ editors are powerful text editors designed specifically for editing Ada and C/C++ source files. They are described in detail in "The Ada Editor" and "The C/C++ Editor" chapters in Programming for Apex. The language editor windows resemble another Apex editor window —— the generic Apex text-editing window which is described in "The Apex Text Editor" chapter of Programming with Apex.
The Apex language editors, like the text editor, contain main buttons for commonly used commands. For example, the Save button duplicates the functionality of the File > Save command, the Search-> button is a shortcut for the Edit > Search menu item, and the Message-> button is a shortcut for the View > Message-> command.
If you are using Ada, type in the code for hello.2.ada as shown in Figure 20.
Figure 20 Ada Editor Window with hello.2.ada
![]()
If you are using C/C++, type in the code hello.C as shown in Figure 21.
Figure 21 C/C++ Editor Window with hello.C Program
![]()
Compiling and Linking a ProgramCommands for compiling and linking Ada and C/C++ programs are available from the Compile menu.
In Apex, a program is always compiled within the compilation context of its enclosing views. The compilation context of a view encompasses the compiler that is used, the values of the compiler's switches, and any imported views that provide external visibility to the units being compiled.
The Ada, text, and C/C++ editor window's Compile menus offers a selection of commands for semanticizing (Ada only), parsing (Ada only), pretty-printing (Ada only), compiling and linking Ada and C/C++ code in the compilation context of their enclosing views. For this brief example, you are going to use the Compile > Link command that compiles and links a program. For details, see "Compiling and Executing" in Programming with Apex.
The procedure for linking mixed language programs is essential the same. It is described in more detail in the Programming with Apex.
When you choose the Compile > Link item from a viewer window, Apex displays the Link dialog box . Note that the name of the selected item will normally be displayed in the Units to Link field.
If you choose Compile > Link from an editor window, Apex links the current object using the Link dialog box defaults. Alternately, you can bring up the Link dialog box by selecting Control-Compile > Link.
For more details on the Compile > Link command, see the Online Reference.
Executing a ProgramTo execute a program, select Run from the File menu. Apex then opens the Run dialog box illustrated in Figure 22.
The Run dialog box allows you to run a program and to redirect input, output, and error output. You can also use the Run dialog box to run programs under the debugger.
Figure 22 Run Dialog Box
![]()
The Run dialog box contains text fields in which you can type the name of the program you want to execute, the UNIX arguments (if any) that you want to pass to the program, and the context in which the program will execute. Note that the Run dialog box is slightly different for native and embedded (cross) systems. Only the Run dialog for native systems is illustrated here. The Run dialog for embedded systems is described in detail in the Programming for {Rational Exec, Tornado, LynxOS} manuals.
You may also choose Tools > Shell to bring up a shell window. In the Window, enter the name of the program to run (hello.exe).
Rational Software Corporation http://www.rational.com support@rational.com techpubs@rational.com Copyright © 1993-2002, Rational Software Corporation. All rights reserved. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |