comp.lang.ada
 help / color / mirror / Atom feed
* Only one compilation unit.
@ 2001-06-15  2:20 McDoobie
  2001-06-15  3:05 ` James Rogers
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: McDoobie @ 2001-06-15  2:20 UTC (permalink / raw)


Alright, I'm writing a small program using two procedures.

Now I'm coding both procedures within the same .adb file. When I go to
compile the program I get an error that says "end of file expected, can
only have one compilation unit."

Now, that only happens when writing programs with more than one procedure.

Do I have to put each different procedure in a seperate text file? Or is
it necessary to write .ads which describe each and every procedure?
Any help would be appreciated.

Thanks.

McDoobie
chris@dont.spam.me



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

* Re: Only one compilation unit.
  2001-06-15  2:20 Only one compilation unit McDoobie
@ 2001-06-15  3:05 ` James Rogers
       [not found] ` <3B297ED4.2BD6DF79@engineer.com>
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: James Rogers @ 2001-06-15  3:05 UTC (permalink / raw)


Gnat requires each compilation unit to be in a separate file.

There is a simple way around this problem. Define one procedure
inside the other.

Jim Rogers
Colorado Springs, Colorado USA

McDoobie wrote:
> 
> Alright, I'm writing a small program using two procedures.
> 
> Now I'm coding both procedures within the same .adb file. When I go to
> compile the program I get an error that says "end of file expected, can
> only have one compilation unit."
> 
> Now, that only happens when writing programs with more than one procedure.
> 
> Do I have to put each different procedure in a seperate text file? Or is
> it necessary to write .ads which describe each and every procedure?
> Any help would be appreciated.
> 
> Thanks.
> 
> McDoobie
> chris@dont.spam.me



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

* Re: Only one compilation unit.
       [not found] ` <3B297ED4.2BD6DF79@engineer.com>
@ 2001-06-15  4:43   ` McDoobie
  0 siblings, 0 replies; 16+ messages in thread
From: McDoobie @ 2001-06-15  4:43 UTC (permalink / raw)


In article <3B297ED4.2BD6DF79@engineer.com>, "B. Douglas Hilton"
<doug.hilton@engineer.com> wrote:

> 
> --------------BA8245C635FE00B674EB8DF5
> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding:
> 7bit
> 
> I ran into this too, but figured it out pretty fast.
> 
> You can nest a procedure almost anywhere in Ada but it must be in the
> "main" compilation unit.
> 
> Example:
> 
> -- Some program "something.adb"
> 
> procedure SomeThing is
> 
>    procedure SubProc is begin
>       ...
>    end SubProc;
> 
> begin
>    SubProc;
> end SomeThing;
> 
> 
> Get the idea?
> 
> - Doug


I got it.

McDoobie chris@dont.spam.me



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

* Re: Only one compilation unit.
  2001-06-15  2:20 Only one compilation unit McDoobie
  2001-06-15  3:05 ` James Rogers
       [not found] ` <3B297ED4.2BD6DF79@engineer.com>
@ 2001-06-15  6:50 ` tmoran
  2001-06-15  9:21 ` David C. Hoos, Sr.
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: tmoran @ 2001-06-15  6:50 UTC (permalink / raw)


>Do I have to put each different procedure in a seperate text file?
  Unless you nest them, GNAT requires one procedure/file.
GNAT /= Ada 95

-------------------------------------------------------------------
"Some politicians believe any desired magic can be done by sufficiently
complicated technology."



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

* Re: Only one compilation unit.
  2001-06-15  2:20 Only one compilation unit McDoobie
                   ` (2 preceding siblings ...)
  2001-06-15  6:50 ` tmoran
@ 2001-06-15  9:21 ` David C. Hoos, Sr.
  2001-06-15 12:53 ` Marc A. Criley
  2001-07-09  9:53 ` John English
  5 siblings, 0 replies; 16+ messages in thread
From: David C. Hoos, Sr. @ 2001-06-15  9:21 UTC (permalink / raw)


Many of the questions asked on comp.lang.ada (such as this one) can be
answered by reading the appropriate section of the GNAT User's Guide.

The GNAT documentation not only provided the rule, but often
provides the rationale for the rule.

Here is the relevant section of the User's Guide:

Handling Files with Multiple Units
The basic compilation model of GNAT requires that a file submitted to
the compiler have only one unit and there be a strict correspondence
between the file name and the unit name.

The gnatchop utility allows both of these rules to be relaxed, allowing
GNAT to process files which contain multiple compilation units and
files with arbitrary file names. gnatchop reads the specified file and
generates one or more output files, containing one unit per file.
The unit and the file name correspond, as required by GNAT.

If you want to permanently restructure a set of "foreign" files so that
they match the GNAT rules, and do the remaining development using
the GNAT structure, you can simply use gnatchop once, generate the
new set of files and work with them from that point on.

Alternatively, if you want to keep your files in the "foreign" format,
perhaps to maintain compatibility with some other Ada compilation
system, you can set up a procedure where you use gnatchop each
time you compile, regarding the source files that it writes as
temporary files that you throw away.

"McDoobie" <someone@nospam.net> wrote in message
news:pheW6.78393$DG1.12883136@news1.rdc1.mi.home.com...
> Alright, I'm writing a small program using two procedures.
>
> Now I'm coding both procedures within the same .adb file. When I go to
> compile the program I get an error that says "end of file expected, can
> only have one compilation unit."
>
> Now, that only happens when writing programs with more than one procedure.
>
> Do I have to put each different procedure in a seperate text file? Or is
> it necessary to write .ads which describe each and every procedure?
> Any help would be appreciated.
>
> Thanks.
>
> McDoobie
> chris@dont.spam.me



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



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

* Re: Only one compilation unit.
  2001-06-15  2:20 Only one compilation unit McDoobie
                   ` (3 preceding siblings ...)
  2001-06-15  9:21 ` David C. Hoos, Sr.
@ 2001-06-15 12:53 ` Marc A. Criley
  2001-07-09  9:53 ` John English
  5 siblings, 0 replies; 16+ messages in thread
From: Marc A. Criley @ 2001-06-15 12:53 UTC (permalink / raw)


McDoobie wrote:
> 
> Alright, I'm writing a small program using two procedures.
> 
> Now I'm coding both procedures within the same .adb file. When I go to
> compile the program I get an error that says "end of file expected, can
> only have one compilation unit."
> 
> Now, that only happens when writing programs with more than one procedure.
> 
> Do I have to put each different procedure in a seperate text file? Or is
> it necessary to write .ads which describe each and every procedure?
> Any help would be appreciated.
> 

You already got the basic answer to your question in the other postings,
but let me just add some info about a common Ada programming idiom.

If you're writing what might be considered a single procedure, but you
don't like doing lots of procedure nesting, you can create a package to
contain the procedures.  (This approach uses packages simply as an
encapsulation mechanism.)  At the one extreme the package could then
provide just a single visible procedure, for example:

   procedure Run;

which is then called by your main program.  On the other hand, if the
package makes visible a few key procedures, then your main program can
implement the high-level logic, orchestrating the calls to this support
package.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



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

* Re: Only one compilation unit.
  2001-06-15  2:20 Only one compilation unit McDoobie
                   ` (4 preceding siblings ...)
  2001-06-15 12:53 ` Marc A. Criley
@ 2001-07-09  9:53 ` John English
  2001-07-09 13:02   ` McDoobie
                     ` (2 more replies)
  5 siblings, 3 replies; 16+ messages in thread
From: John English @ 2001-07-09  9:53 UTC (permalink / raw)


McDoobie wrote:
> 
> Alright, I'm writing a small program using two procedures.
> 
> Now I'm coding both procedures within the same .adb file. When I go to
> compile the program I get an error that says "end of file expected, can
> only have one compilation unit."
> 
> Now, that only happens when writing programs with more than one procedure.
> 
> Do I have to put each different procedure in a seperate text file?

For GNAT, yes.

Simple solution: if you have x.adb containing procedure Main and procedure Sub,
run "gnatchop x.adb" which will split the procedures into separate files called
main.adb and sub.adb, then run "gnatmake main.adb" which will compile Main and
any other units that it depends on (in this case, Sub). Note that Main will
need to say "with Sub;" at the top...

> Or is
> it necessary to write .ads which describe each and every procedure?

No.

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.comp.it.bton.ac.uk/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

* Re: Only one compilation unit.
  2001-07-09  9:53 ` John English
@ 2001-07-09 13:02   ` McDoobie
  2001-07-10  0:19   ` Keith Thompson
  2001-07-13 19:08   ` Simon Wright
  2 siblings, 0 replies; 16+ messages in thread
From: McDoobie @ 2001-07-09 13:02 UTC (permalink / raw)


In article <3B497F21.8CD784D8@brighton.ac.uk>, John English
<je@brighton.ac.uk> wrote:


> For GNAT, yes.
> 
> Simple solution: if you have x.adb containing procedure Main and
> procedure Sub, run "gnatchop x.adb" which will split the procedures into
> separate files called main.adb and sub.adb, then run "gnatmake main.adb"
> which will compile Main and any other units that it depends on (in this
> case, Sub). Note that Main will need to say "with Sub;" at the top...
> 
>> Or is it necessary to write .ads which describe each and every
>> procedure?
> 
> No.

Gnatchop is turning out to be very handy.

I intend to make use of it more often.

Thank you.

McDoobie
chris@dont.spam.me



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

* Re: Only one compilation unit.
  2001-07-09  9:53 ` John English
  2001-07-09 13:02   ` McDoobie
@ 2001-07-10  0:19   ` Keith Thompson
  2001-07-13 19:08   ` Simon Wright
  2 siblings, 0 replies; 16+ messages in thread
From: Keith Thompson @ 2001-07-10  0:19 UTC (permalink / raw)


John English <je@brighton.ac.uk> writes:
> McDoobie wrote:
> > 
> > Alright, I'm writing a small program using two procedures.
> > 
> > Now I'm coding both procedures within the same .adb file. When I go to
> > compile the program I get an error that says "end of file expected, can
> > only have one compilation unit."
> > 
> > Now, that only happens when writing programs with more than one procedure.
> > 
> > Do I have to put each different procedure in a seperate text file?
> 
> For GNAT, yes.

GNAT requires each library unit to be in a separate file.  Nested
procedures, of course, can be in the same file.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Cxiuj via bazo apartenas ni.



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

* Re: Only one compilation unit.
  2001-07-09  9:53 ` John English
  2001-07-09 13:02   ` McDoobie
  2001-07-10  0:19   ` Keith Thompson
@ 2001-07-13 19:08   ` Simon Wright
  2001-07-15 11:40     ` Larry Kilgallen
  2001-07-16  1:56     ` Robert Dewar
  2 siblings, 2 replies; 16+ messages in thread
From: Simon Wright @ 2001-07-13 19:08 UTC (permalink / raw)


John English <je@brighton.ac.uk> writes:

> McDoobie wrote:
> > 
> > Alright, I'm writing a small program using two procedures.
> > 
> > Now I'm coding both procedures within the same .adb file. When I go to
> > compile the program I get an error that says "end of file expected, can
> > only have one compilation unit."
> > 
> > Now, that only happens when writing programs with more than one procedure.
> > 
> > Do I have to put each different procedure in a seperate text file?
> 
> For GNAT, yes.
> 
> Simple solution: if you have x.adb containing procedure Main and
> procedure Sub, run "gnatchop x.adb" which will split the procedures
> into separate files called main.adb and sub.adb, then run "gnatmake
> main.adb" which will compile Main and any other units that it
> depends on (in this case, Sub). Note that Main will need to say
> "with Sub;" at the top...

It's probably a good idea to name the file containing your source
using a file extension other than .adb or .ads (or .adp or .adc, in
case you take up extended features later). I'd use .ada

We had fun when the source was called Foo.ads, under NT one of the
split files ended up also called Foo.ads -- which overwrote our
original. Also, GNAT does *not* like files with upper-case letters in
the name at all!



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

* Re: Only one compilation unit.
  2001-07-13 19:08   ` Simon Wright
@ 2001-07-15 11:40     ` Larry Kilgallen
  2001-07-16 13:41       ` B.Gaffney
  2001-07-16  1:56     ` Robert Dewar
  1 sibling, 1 reply; 16+ messages in thread
From: Larry Kilgallen @ 2001-07-15 11:40 UTC (permalink / raw)


In article <x7vu20gzlxq.fsf@smaug.pushface.org>, Simon Wright <simon@pushface.org> writes:
> John English <je@brighton.ac.uk> writes:
> 
>> McDoobie wrote:
>> > 
>> > Alright, I'm writing a small program using two procedures.
>> > 
>> > Now I'm coding both procedures within the same .adb file. When I go to
>> > compile the program I get an error that says "end of file expected, can
>> > only have one compilation unit."
>> > 
>> > Now, that only happens when writing programs with more than one procedure.
>> > 
>> > Do I have to put each different procedure in a seperate text file?
>> 
>> For GNAT, yes.
>> 
>> Simple solution: if you have x.adb containing procedure Main and
>> procedure Sub, run "gnatchop x.adb" which will split the procedures
>> into separate files called main.adb and sub.adb, then run "gnatmake
>> main.adb" which will compile Main and any other units that it
>> depends on (in this case, Sub). Note that Main will need to say
>> "with Sub;" at the top...
> 
> It's probably a good idea to name the file containing your source
> using a file extension other than .adb or .ads (or .adp or .adc, in
> case you take up extended features later). I'd use .ada

What does .adc mean (outside the context of Compaq (nee DEC (nee VAX)) Ada ?

> We had fun when the source was called Foo.ads, under NT one of the
> split files ended up also called Foo.ads -- which overwrote our
> original. Also, GNAT does *not* like files with upper-case letters in
> the name at all!

Even on VMS ?



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

* Re: Only one compilation unit.
  2001-07-13 19:08   ` Simon Wright
  2001-07-15 11:40     ` Larry Kilgallen
@ 2001-07-16  1:56     ` Robert Dewar
  2001-07-17 18:49       ` Simon Wright
  1 sibling, 1 reply; 16+ messages in thread
From: Robert Dewar @ 2001-07-16  1:56 UTC (permalink / raw)


Simon Wright <simon@pushface.org> wrote in message news:<x7vu20gzlxq.fsf@smaug.pushface.org>...
> We had fun when the source was called Foo.ads, under NT one of the
> split files ended up also called Foo.ads -- which overwrote our
> original.

gnatchop will never overwrite a file unless you spefically ask it to
using the overwrite switch, in which case you can hardly complain :-)

> Also, GNAT does *not* like files with upper-case letters in
> the name at all!

There are no such restrictions in GNAT. Check the section in the users
guide on file naming, if you are having trouble, you are not following
the rules in this section!



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

* Re: Only one compilation unit.
  2001-07-15 11:40     ` Larry Kilgallen
@ 2001-07-16 13:41       ` B.Gaffney
  2001-07-16 15:08         ` Larry Kilgallen
  0 siblings, 1 reply; 16+ messages in thread
From: B.Gaffney @ 2001-07-16 13:41 UTC (permalink / raw)


Kilgallen@eisner.decus.org.nospam (Larry Kilgallen) wrote in message news:<1luFIcjdO+HI@eisner.encompasserve.org>...
> In article <x7vu20gzlxq.fsf@smaug.pushface.org>, Simon Wright <simon@pushface.org> writes:
> > John English <je@brighton.ac.uk> writes:
> > 
...
> > We had fun when the source was called Foo.ads, under NT one of the
> > split files ended up also called Foo.ads -- which overwrote our
> > original. Also, GNAT does *not* like files with upper-case letters in
> > the name at all!
> 
> Even on VMS ?

I don't believe so, I think this is specific to Windows.

I had a problem with this and GnatMake told me to submit it as a bug,
which I did.  The reply I got was that GNAT was working correctly.

If I had to guess (with fear of being corrected), I'd say that, while
Win32 allow mixed case, it is case-insensitive, and some of the tools
GNATMAKE uses are UNIX-based and case-sensitive.  This probably
wouldn't cause a problem on an OS that either didn't care about case
(i.e. VMS) or was case-sensitive.

                             --Brian
                             "Some of our views are spacious
                             "And some are merely spaced."



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

* Re: Only one compilation unit.
  2001-07-16 13:41       ` B.Gaffney
@ 2001-07-16 15:08         ` Larry Kilgallen
  0 siblings, 0 replies; 16+ messages in thread
From: Larry Kilgallen @ 2001-07-16 15:08 UTC (permalink / raw)


In article <9f6e2b77.0107160541.10707819@posting.google.com>, B_Gaffney@My-Deja.com (B.Gaffney) writes:
> Kilgallen@eisner.decus.org.nospam (Larry Kilgallen) wrote in message news:<1luFIcjdO+HI@eisner.encompasserve.org>...
>> In article <x7vu20gzlxq.fsf@smaug.pushface.org>, Simon Wright <simon@pushface.org> writes:
>> > John English <je@brighton.ac.uk> writes:
>> > 
> ...
>> > We had fun when the source was called Foo.ads, under NT one of the
>> > split files ended up also called Foo.ads -- which overwrote our
>> > original. Also, GNAT does *not* like files with upper-case letters in
>> > the name at all!
>> 
>> Even on VMS ?
> 
> I don't believe so, I think this is specific to Windows.
> 
> I had a problem with this and GnatMake told me to submit it as a bug,
> which I did.  The reply I got was that GNAT was working correctly.
> 
> If I had to guess (with fear of being corrected), I'd say that, while
> Win32 allow mixed case, it is case-insensitive, and some of the tools
> GNATMAKE uses are UNIX-based and case-sensitive.  This probably
> wouldn't cause a problem on an OS that either didn't care about case
> (i.e. VMS) or was case-sensitive.

As I see it, the VMS situation should be comparable to that on Windows
when the VMS system is using ODS-5 disks, which are case-insensitive but
case-preserving.



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

* Re: Only one compilation unit.
  2001-07-16  1:56     ` Robert Dewar
@ 2001-07-17 18:49       ` Simon Wright
  2001-07-18  7:53         ` Robert Dewar
  0 siblings, 1 reply; 16+ messages in thread
From: Simon Wright @ 2001-07-17 18:49 UTC (permalink / raw)


dewar@gnat.com (Robert Dewar) writes:

> Simon Wright <simon@pushface.org> wrote in message news:<x7vu20gzlxq.fsf@smaug.pushface.org>...
> > We had fun when the source was called Foo.ads, under NT one of the
> > split files ended up also called Foo.ads -- which overwrote our
> > original.
> 
> gnatchop will never overwrite a file unless you spefically ask it to
> using the overwrite switch, in which case you can hardly complain :-)

I think you may have a point there. Even so, it seems unexpected for
it to overwrite the input file .. and copying the casing of the
existing file name, rather than lower case, didn't help.

> > Also, GNAT does *not* like files with upper-case letters in
> > the name at all!
> 
> There are no such restrictions in GNAT. Check the section in the users
> guide on file naming, if you are having trouble, you are not following
> the rules in this section!

Well, I guess I was considering the whole galaxy of GNAT utilities --
whatever it is you run when you type C-c C-d (ada-goto-declaration)
certainly got confused for us, and the confusion went away when we
made the file names all lower-case.



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

* Re: Only one compilation unit.
  2001-07-17 18:49       ` Simon Wright
@ 2001-07-18  7:53         ` Robert Dewar
  0 siblings, 0 replies; 16+ messages in thread
From: Robert Dewar @ 2001-07-18  7:53 UTC (permalink / raw)


Simon Wright <simon@pushface.org> wrote in message news:<x7vd76zjsra.fsf@smaug.pushface.org>...

> Well, I guess I was considering the whole galaxy of GNAT utilities --
> whatever it is you run when you type C-c C-d (ada-goto-declaration)
> certainly got confused for us, and the confusion went away when we
> made the file names all lower-case.

If you use non-standard names for files (and file names that are not
all lower case are considered non-standard), then you need to look in
the chapter in the users guide and carry out the necessary steps to
inform GNAT of what file names you will be using. If you don't do this
you will indeed run into confusion (this is simply a special case of
the general rule that if you don't follow the documentation, you may
run into confusion :-)



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

end of thread, other threads:[~2001-07-18  7:53 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-15  2:20 Only one compilation unit McDoobie
2001-06-15  3:05 ` James Rogers
     [not found] ` <3B297ED4.2BD6DF79@engineer.com>
2001-06-15  4:43   ` McDoobie
2001-06-15  6:50 ` tmoran
2001-06-15  9:21 ` David C. Hoos, Sr.
2001-06-15 12:53 ` Marc A. Criley
2001-07-09  9:53 ` John English
2001-07-09 13:02   ` McDoobie
2001-07-10  0:19   ` Keith Thompson
2001-07-13 19:08   ` Simon Wright
2001-07-15 11:40     ` Larry Kilgallen
2001-07-16 13:41       ` B.Gaffney
2001-07-16 15:08         ` Larry Kilgallen
2001-07-16  1:56     ` Robert Dewar
2001-07-17 18:49       ` Simon Wright
2001-07-18  7:53         ` Robert Dewar

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