TutorialTool Integration




Prev | Up | Next | Back | Forward | Online Documentation Home Page

Tool Integration

This chapter introduces some of the ways in which Ada-ASSURED can integrate with other tools. The material is described in the following sections:

Compiler Integration

Ada-ASSURED's compile command invokes an Ada compiler and directs its error messages to the Ada-ASSURED buffer named *compilation*. The next-error command sequences through these errors, opening the offending file (if necessary) and selecting the appropriate line.

Ada-ASSURED is delivered with the option to integrate with many popular compilers. At installation time, one of these compilers was chosen as the default. This section describes:

Choosing a Compiler

File Ada-ASSURED/scripts/compiler-commands.stk contains a table of all compiler integrations delivered with Ada-ASSURED. Each compiler has a name used as a key for indexing the table.

The script language variable sg:compiler-choice contains the name of the compiler currently bound to the compile command. The variable is initialized with the default compiler that was chosen at installation time.

To change the default compiler, just assign sg:compiler-choice a different compiler name. For example, to use the GNU Ada compiler, execute the script language statement

(set! sg:compiler-choice "GNAT")
This can be done while Ada-ASSURED is running using eval-string, or at startup by including the statement in a startup script.

See file Ada-ASSURED/scripts/compiler-commands.stk for the names of integrated compilers. See Chapter Scripting Language for details on startup scripts.

Integrating a Compiler

The commands this-error and next-error operate on compiler output lines that have the following canonical format:

file-name : line-number : text
Compilation output lines having any other format are ignored by these commands.

Compiler integration consists in specifying the means for calling a given compiler and filtering its error messages into the canonical format. The script language variable sg:compiler-command-data contains the table of integrated compilers. Each entry in the table is a sextuple, as follows:

To integrate an additional compiler, just add an entry to sg:compiler-command-data, either by editing file Ada-ASSURED/scripts/compiler-commands.stk directly, or by updating the variable appropriately in a startup script. Note that the tool invoked by the compile command need not be a compiler.

As an example, consider this compiler entry for the fictitious TorquemAda compiler.

   ("TorquemAda_2000"
    "torque.exe \"%F\""
    "2>&1"
    ,(lambda (s)
      (regexp-replace "([^:]*): line (.*) col" s "\\2:\\1: col")
      (set! torque-count (+ torque-count 1)))
    ,(lambda () (eval '(define torque-count 0)))
    ,(lambda () (sg:write-message (format #f "~a lines" torque-count))))

The filter string is used to redirect standard error to the standard output.

The compilation scheme filter entry is a closure of one argument, used to filter the compiler lines (and to count them). It has the effect of translating, say

    foo.ada : Error: line 17 col 3 -- undeclared identifier.
to
    foo.ada : 17 : Error : col 3 -- undeclared identifier.

The compiler scheme filter initialization entry defines a global variable used to count the number of error lines.

The compiler scheme filter finalization entry is a closure of zero arguments.

Technical notes:

The reason for the antiquotation of (i.e., the comma preceding) the lambda expressions is that the compiler entries are made within the context of quasiquotation (`(...)): they must be antiquoted to become ordinary expressions again. Quoted strings are unaffected by quasiquotation, and thus do not require antiquotation.

The reason that

    ,(lambda () (eval '(define torque-count 0)))
is used instead of
    ,(lambda () (define torque-count 0))
is so that torque-count will be defined in the global environment, and thus be available to the compilation scheme filter closure.

Running as Server

Ada-ASSURED can run as a server, responding to messages received from other tools. The messages are scripts that Ada-ASSURED executes. For example, if Ada-ASSURED receives the message:

(sg:open "demo.a" "compilation" "No") (sg:goto-xline 100)
then file demo.a will be opened with line 100 selected. Utility routine sg-client is provided for sending messages to Ada-ASSURED. For example, execution of
sg-client -instance aa83 -startup aahome/bin/aa83
   -command "(sg:open "demo.a" "compilation" "No") (sg:goto-xline 100)"
will send the given message to all Ada-ASSURED processes running on the given display. If none is running, aa83 will be invoked first. Note that the above command should be entered all on one line.

See the man entry for sg-client for further details.

Running as Client

Ada-ASSURED can invoke other tools, either directly using shell-command, or from within a script. Here is an example for each windowing system.

X

Suppose, for example, that you wish to escape to vi to perform some special editing action on the current structural selection. This can be done by invoking the following script procedure vi:

(define (vi)
   (sg:save-selection-to-file "Text" "/tmp/ssel" "BASEVIEW")
   (system "xterm -e /usr/ucb/vi /tmp/ssel")
   (sg:cut-structure)
   (sg:insert-file-structure "/tmp/ssel"))
This script works as follows: Script procedure vi can be invoked by using eval-string to evaluate the expression (vi).

MS

Suppose, for example, that you wish to escape to notepad to perform some special editing action on the current structural selection. This can be done by invoking the following script procedure notepad:

(define (notepad)
   (sg:save-selection-to-file "Text" "C:/temp/ssel" "BASEVIEW")
   (system "notepad C:/temp/ssel")
   (sg:cut-structure)
   (sg:insert-file-structure "C:/temp/ssel"))
This script works as follows: Script procedure notepad can be invoked by using eval-string to evaluate the expression (notepad).


Forward