| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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 |
|
#4
| |||
| |||
| 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. |
|
#5
| |||
| |||
| > 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... |
|
#6
| |||
| |||
| 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 |
|
#7
| |||
| |||
| 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. |
|
#8
| |||
| |||
| > > 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. |
|
#9
| |||
| |||
| 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))) |
|
#10
| |||
| |||
| 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/list...ephe-leake.org -- -- Stephe |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.