comp.lang.ada
 help / color / mirror / Atom feed
* simple programs -> one file with gps 2008 (gpl)?
@ 2008-08-08 19:12 Marcus Lauster
  2008-08-08 20:25 ` Jeffrey R. Carter
  2008-08-08 22:44 ` amado.alves
  0 siblings, 2 replies; 10+ messages in thread
From: Marcus Lauster @ 2008-08-08 19:12 UTC (permalink / raw)


Hi,

I'm new to Ada and therefore I'm digging through the book "Programming 
in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple 
Programms might be presented in a single file." Furthermore he outlines 
the structure of how such a simple program might look.

package x is -- spec and body of Objects
with x; use x;
package xx is --
with xx; use xx;
...
procedure Main is...

I typed a program with similar structure into GPS 2008 (GPL) and while 
trying to compile the GPS compiler aborted with the following message

"end of file expected, file can have only one compilation unit"

So my question is how to convince the underlying compiler of GPS that my 
program is a simple program.

Regards




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-08 19:12 simple programs -> one file with gps 2008 (gpl)? Marcus Lauster
@ 2008-08-08 20:25 ` Jeffrey R. Carter
  2008-08-08 20:54   ` [Solved] " Marcus Lauster
                     ` (2 more replies)
  2008-08-08 22:44 ` amado.alves
  1 sibling, 3 replies; 10+ messages in thread
From: Jeffrey R. Carter @ 2008-08-08 20:25 UTC (permalink / raw)


Marcus Lauster wrote:
> 
> I'm new to Ada and therefore I'm digging through the book "Programming 
> in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple 
> Programms might be presented in a single file." Furthermore he outlines 
> the structure of how such a simple program might look.

The operative word here is "might". There's not much in the ARM about source 
files or the relationship of compilation units to source files. There's nothing 
in the ARM to prevent a compiler from accepting multiple compilation units in a 
single file, but there's also nothing to require it.

GNAT, the compiler you're using, does not accept multiple compilation units in a 
single file. To ease migration of code from other compilers that do, it provides 
the gnatchop program that will break a file containing multiple compilation 
units into multiple files, each containing a single unit.

> I typed a program with similar structure into GPS 2008 (GPL) and while 
> trying to compile the GPS compiler aborted with the following message

GPS is an IDE, not a compiler. By default it uses the GNAT compiler, so no doubt 
you're using GNAT 2008.

> So my question is how to convince the underlying compiler of GPS that my 
> program is a simple program.

I'm not aware of any way to get GNAT to accept multiple compilation units in a 
single file.

-- 
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Solved] Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-08 20:25 ` Jeffrey R. Carter
@ 2008-08-08 20:54   ` Marcus Lauster
  2008-08-08 21:29   ` Ed Falis
  2008-08-11  8:44   ` Lucretia
  2 siblings, 0 replies; 10+ messages in thread
From: Marcus Lauster @ 2008-08-08 20:54 UTC (permalink / raw)


Jeffrey R. Carter schrieb:
> Marcus Lauster wrote:
>>
>> [...]  Furthermore he
>> outlines the structure of how such a simple program might look.
> 
> The operative word here is "might". [...]

In my youthful enthusiasm I didn't process this word correctly. ;)

>> I typed a program with similar structure into GPS 2008 (GPL) and while 
>> trying to compile the GPS compiler aborted with the following message
> 
> GPS is an IDE, not a compiler.[...]

I know.

>> So my question is how to convince the underlying compiler of GPS that 
>> my program is a simple program.
> 
> I'm not aware of any way to get GNAT to accept multiple compilation 
> units in a single file.

Good to know and thanks for your time and the appropriate information.

Regards



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-08 20:25 ` Jeffrey R. Carter
  2008-08-08 20:54   ` [Solved] " Marcus Lauster
@ 2008-08-08 21:29   ` Ed Falis
  2008-08-11  8:44   ` Lucretia
  2 siblings, 0 replies; 10+ messages in thread
From: Ed Falis @ 2008-08-08 21:29 UTC (permalink / raw)


On Fri, 08 Aug 2008 16:25:44 -0400, Jeffrey R. Carter  
<spam.jrcarter.not@spam.acm.org> wrote:

> I'm not aware of any way to get GNAT to accept multiple compilation  
> units in a single file.

There's a description somewhere in the GNAT User Guide of how to do this.   
More trouble than it's worth unless you have a compelling CM/process need  
for it.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-08 19:12 simple programs -> one file with gps 2008 (gpl)? Marcus Lauster
  2008-08-08 20:25 ` Jeffrey R. Carter
@ 2008-08-08 22:44 ` amado.alves
  2008-08-10 22:25   ` Robert A Duff
  1 sibling, 1 reply; 10+ messages in thread
From: amado.alves @ 2008-08-08 22:44 UTC (permalink / raw)


> I'm new to Ada and therefore I'm digging through the book "Programming
> in Ada 2005".

Welcome!

> "Complete simple programms might be presented in a single file."

Probably this was just to stress that the language is not file-
oriented like C or Java.

However, for better and for worse, GNAT is a file-oriented compiler.

Like others have said (and yet others seem to ignore) a tool Gnatchop
exists that generates the files from an Ada text (usually from an .ada
file) Eventually you use this tool to start development from an Ada
text. But normally you only do this once at the start of development,
because compiler messages will point to the 'new' files, so it's more
convenient to edit them instead of the old, and there is no tool to
keep the new and the old in sync automatically.

If you use GPS then probably you will use the respective "project"
tools and the "visual" programming style to "manage" the files. Beware
of visual spaggetti...



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-08 22:44 ` amado.alves
@ 2008-08-10 22:25   ` Robert A Duff
  2008-08-12 10:21     ` amado.alves
  0 siblings, 1 reply; 10+ messages in thread
From: Robert A Duff @ 2008-08-10 22:25 UTC (permalink / raw)


amado.alves@gmail.com writes:

> Like others have said (and yet others seem to ignore) a tool Gnatchop
> exists that generates the files from an Ada text (usually from an .ada
> file) Eventually you use this tool to start development from an Ada
> text. But normally you only do this once at the start of development,
> because compiler messages will point to the 'new' files, so it's more
> convenient to edit them instead of the old,...

The -r switch to gnatchop causes error messages to refer to the original
pre-chopped file.  The -w and -p switches are also quite useful -- look
at the docs.

I agree that GNAT's bias toward one-comp-unit-per-file is an annoying
feature.  A minor annoyance at most, since that's usually what you want
anyway.

- Bob



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-08 20:25 ` Jeffrey R. Carter
  2008-08-08 20:54   ` [Solved] " Marcus Lauster
  2008-08-08 21:29   ` Ed Falis
@ 2008-08-11  8:44   ` Lucretia
  2 siblings, 0 replies; 10+ messages in thread
From: Lucretia @ 2008-08-11  8:44 UTC (permalink / raw)


On Aug 8, 9:25 pm, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> Marcus Lauster wrote:
>
> > I'm new to Ada and therefore I'm digging through the book "Programming
> > in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple
> > Programms might be presented in a single file." Furthermore he outlines
> > the structure of how such a simple program might look.
>
> The operative word here is "might". There's not much in the ARM about source
> files or the relationship of compilation units to source files. There's nothing
> in the ARM to prevent a compiler from accepting multiple compilation units in a
> single file, but there's also nothing to require it.

While the AARM does not state anything about how a compilation unit
and a file relate to each other, it does state that a compiler should
take a number of compilation units (see 10.1), this is even specified
in the EBNF (appendix P):

10.1.1:
compilation::= {compilation_unit}

GNAT provides this using gnatchop, there are messages from Robert
Dewar on this group about this.

Thanks,
Luke.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-10 22:25   ` Robert A Duff
@ 2008-08-12 10:21     ` amado.alves
  2008-08-12 17:03       ` Simon Wright
  0 siblings, 1 reply; 10+ messages in thread
From: amado.alves @ 2008-08-12 10:21 UTC (permalink / raw)


> > file) Eventually you use this tool to start development from an Ada
> > text. But normally you only do this once at the start of development,
> > because compiler messages will point to the 'new' files, so it's more
> > convenient to edit them instead of the old,...
>
> The -r switch to gnatchop causes error messages to refer to the original
> pre-chopped file.

Indeed! I stand corrected. This is wonderful. You can work based
on .ada files :-)
Thanks for pointing this out.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-12 10:21     ` amado.alves
@ 2008-08-12 17:03       ` Simon Wright
  2008-08-13 12:45         ` Stephen Leake
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Wright @ 2008-08-12 17:03 UTC (permalink / raw)


amado.alves@gmail.com writes:

>> > file) Eventually you use this tool to start development from an Ada
>> > text. But normally you only do this once at the start of development,
>> > because compiler messages will point to the 'new' files, so it's more
>> > convenient to edit them instead of the old,...
>>
>> The -r switch to gnatchop causes error messages to refer to the original
>> pre-chopped file.
>
> Indeed! I stand corrected. This is wonderful. You can work based
> on .ada files :-)
> Thanks for pointing this out.

If you are an Emacs user, I have written a minor mode (gnatchop-mode) so
that every time you save the big source file gnatchop (-r) is run on it.

Um, I guess I should offer it to ada-mode -- tried that when AdaCore
were running it, it wasn't general enough for them (but works for me!)

;; gnatchop.el
;; Copyright (C) 2001 Simon Wright <simon@pushface.org>.
;; $Id: gnatchop.el,v 1.1 2001/12/01 06:58:43 simon Exp $

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.

;; Minor mode for use in Ada buffers that don't have the correct file name
;; for use with GNAT, and which therefore need to be "gnatchop"'d before
;; compilation.

;; Reference: Writing GNU Emacs Extensions by Bob Glickstein (O'Reilly
;; & Associates, Inc, 1997).

(defvar gnatchop-mode nil
  "Mode variable for gnatchop minor mode.")

(defun gnatchop-mode (&optional arg)
  "Gnatchop minor mode."
  (interactive "P")
  (make-variable-buffer-local 'gnatchop-mode)
  (make-local-hook 'after-save-hook)
  (setq gnatchop-mode
	(if (null arg)
	    (not gnatchop-mode)
	  (> (prefix-numeric-value arg) 0)))
  (if gnatchop-mode
      (add-hook 'after-save-hook 'gnatchop-file)
    (remove-hook 'after-save-hook 'gnatchop-file))
)

(defun gnatchop-file ()
  "Run gnatchop on current buffer's file after save."
  (if gnatchop-mode
      (progn
	(message (concat "chopping " (buffer-file-name)))
	(let (compilation-read-command
	      (compilation-buffer-name-function
	       (lambda (mode) "*Gnatchop*")))
	  (compile (concat "gnatchop -w -r " (buffer-file-name)))
	  (bury-buffer (get-buffer "*Gnatchop*")))))
)

(if (not (assq 'gnatchop-mode minor-mode-alist))
    (setq minor-mode-alist
	  (cons '(gnatchop-mode " Chop")
		minor-mode-alist)))



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: simple programs -> one file with gps 2008 (gpl)?
  2008-08-12 17:03       ` Simon Wright
@ 2008-08-13 12:45         ` Stephen Leake
  0 siblings, 0 replies; 10+ messages in thread
From: Stephen Leake @ 2008-08-13 12:45 UTC (permalink / raw)


Simon Wright <simon.j.wright@mac.com> writes:

> If you are an Emacs user, I have written a minor mode (gnatchop-mode) so
> that every time you save the big source file gnatchop (-r) is run on it.
>
> Um, I guess I should offer it to ada-mode -- tried that when AdaCore
> were running it, it wasn't general enough for them (but works for
> me!)

As the maintainer of Ada mode, I think this is more properly done in a
Makefile. 

But it is possible to use Emacs Ada mode for pure Ada projects without
a Makefile, so I suppose it would make sense to include it as an
option.

> ;; gnatchop.el
> ;; Copyright (C) 2001 Simon Wright <simon@pushface.org>.
> ;; $Id: gnatchop.el,v 1.1 2001/12/01 06:58:43 simon Exp $

Since Ada mode is part of Emacs, you would need to assign copyright to
the Free Software Foundation; email me off list about this.

> ;; Minor mode for use in Ada buffers that don't have the correct file name
> ;; for use with GNAT, and which therefore need to be "gnatchop"'d before
> ;; compilation.

"wrong file name" does not require gnatchop (you can specify other
names in the GNAT project file), only "multiple compilation units".

We should move other discussion about this to the Emacs Ada mode
mailing list hosted at
http://stephe-leake.org/mailman/listinfo/emacs-ada-mode_stephe-leake.org 

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-08-13 12:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-08 19:12 simple programs -> one file with gps 2008 (gpl)? Marcus Lauster
2008-08-08 20:25 ` Jeffrey R. Carter
2008-08-08 20:54   ` [Solved] " Marcus Lauster
2008-08-08 21:29   ` Ed Falis
2008-08-11  8:44   ` Lucretia
2008-08-08 22:44 ` amado.alves
2008-08-10 22:25   ` Robert A Duff
2008-08-12 10:21     ` amado.alves
2008-08-12 17:03       ` Simon Wright
2008-08-13 12:45         ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox