comp.lang.ada
 help / color / mirror / Atom feed
* Non-Stub In Inner Scope?
@ 2001-05-19 21:42 Dr Nancy's Sweetie
  2001-05-19 22:01 ` David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dr Nancy's Sweetie @ 2001-05-19 21:42 UTC (permalink / raw)



I'm having trouble with the problem of separate compilation.  If I
try this:
 

    with Ada.Text_Io;
    package body Example is
       procedure Put_Line(Text: String) is
          function Wont_Work(Text: String) return String is separate;
       begin
          Ada.Text_Io.Put_Line(Wont_Work(Text));
       end Put_Line;
    end Example;


GNAT gets to the function Wont_Work() and says:

	example.adb:4:07: stub cannot appear in an inner scope


I can just move the stub for Wont_Work() into the package spec, but it
doesn't properly belong there: that would make it "global" to all the
parts of the package, and it is only needed in this one place.

I see two obvious solutions:

 1) The C-style solution, which is to move the stub into the package spec,
    and thus have it accessable by every part of the package.  I don't
    like this because one reason to use Ada is that you can have local
    functions.

 2) The Pascal-style solution, which is to cram the whole function (and
    it's really long, and there are several of them) into the declaration
    section of the Put_Line() procedure.  I don't like this one, because
    because it means that between the line "procedure Put_Line(...) is"
    and the associated "begin", I would have almost 500 lines of code.

Both solutions also have the problem that I'd have to have the body of
Wont_Work() in the example.adb file, making it impossible to do separate
compilation.  There are several functions that go along with Wont_Work(),
and they're pretty long.  They are debugged and stable at this point,
which is why I wanted to move them out; the rest of the package is still
in flux.  Recompiling that code over and over can consume a lot of time.

Is it possible in Ada to write a package such that the source for its
functions and procedures is in more than one file?

Or am I just going about this in some non-Ada-y fashion?  (I confess
to being new at this.)


Darren Provine ! kilroy@copland.rowan.edu ! http://www.rowan.edu/~kilroy
"I use not only all the brains I have, but all those I can borrow as well."
                                                  -- Woodrow Wilson



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

* Re: Non-Stub In Inner Scope?
  2001-05-19 21:42 Non-Stub In Inner Scope? Dr Nancy's Sweetie
@ 2001-05-19 22:01 ` David C. Hoos, Sr.
  2001-05-19 23:08   ` Robert A Duff
  2001-05-20 10:50   ` RPrice9979
  2001-05-20  3:15 ` Jeffrey Carter
  2001-05-20 12:29 ` Marc A. Criley
  2 siblings, 2 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 2001-05-19 22:01 UTC (permalink / raw)


Just move the stub outside of the subprogram which now encloses it.
It will be in the package body and visible to all subprograms which
follow its declaration, but it will not be visible to clients of the
package, because it doesn't appear in the package spec.

"Dr Nancy's Sweetie" <kilroy@copland.rowan.edu> wrote in message
news:NMBN6.5769$DW1.255373@iad-read.news.verio.net...
>
> I'm having trouble with the problem of separate compilation.  If I
> try this:
>
>
>     with Ada.Text_Io;
>     package body Example is
>        procedure Put_Line(Text: String) is
>           function Wont_Work(Text: String) return String is separate;
>        begin
>           Ada.Text_Io.Put_Line(Wont_Work(Text));
>        end Put_Line;
>     end Example;
>
>
> GNAT gets to the function Wont_Work() and says:
>
> example.adb:4:07: stub cannot appear in an inner scope
>
>
> I can just move the stub for Wont_Work() into the package spec, but it
> doesn't properly belong there: that would make it "global" to all the
> parts of the package, and it is only needed in this one place.
>
> I see two obvious solutions:
>
>  1) The C-style solution, which is to move the stub into the package spec,
>     and thus have it accessable by every part of the package.  I don't
>     like this because one reason to use Ada is that you can have local
>     functions.
>
>  2) The Pascal-style solution, which is to cram the whole function (and
>     it's really long, and there are several of them) into the declaration
>     section of the Put_Line() procedure.  I don't like this one, because
>     because it means that between the line "procedure Put_Line(...) is"
>     and the associated "begin", I would have almost 500 lines of code.
>
> Both solutions also have the problem that I'd have to have the body of
> Wont_Work() in the example.adb file, making it impossible to do separate
> compilation.  There are several functions that go along with Wont_Work(),
> and they're pretty long.  They are debugged and stable at this point,
> which is why I wanted to move them out; the rest of the package is still
> in flux.  Recompiling that code over and over can consume a lot of time.
>
> Is it possible in Ada to write a package such that the source for its
> functions and procedures is in more than one file?
>
> Or am I just going about this in some non-Ada-y fashion?  (I confess
> to being new at this.)
>
>
> Darren Provine ! kilroy@copland.rowan.edu ! http://www.rowan.edu/~kilroy
> "I use not only all the brains I have, but all those I can borrow as
well."
>                                                   -- Woodrow Wilson




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

* Re: Non-Stub In Inner Scope?
  2001-05-19 22:01 ` David C. Hoos, Sr.
@ 2001-05-19 23:08   ` Robert A Duff
  2001-05-20 10:50   ` RPrice9979
  1 sibling, 0 replies; 7+ messages in thread
From: Robert A Duff @ 2001-05-19 23:08 UTC (permalink / raw)


"David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> writes:

> Just move the stub outside of the subprogram which now encloses it.

Yes, or put Wont_Work into a child package.

> > I'm having trouble with the problem of separate compilation.  If I
> > try this:
> >
> >     with Ada.Text_Io;
> >     package body Example is
> >        procedure Put_Line(Text: String) is
> >           function Wont_Work(Text: String) return String is separate;
> >        begin
> >           Ada.Text_Io.Put_Line(Wont_Work(Text));
> >        end Put_Line;
> >     end Example;

If Put_Line were also a subunit, it would work.  There's no particularly
good reason for it to work this way (IMHO), but that's the way it is:
you can't have a subunit more deeply nested like that.

But I generally prefer child units to subunits anyway...

- Bob



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

* Re: Non-Stub In Inner Scope?
  2001-05-19 21:42 Non-Stub In Inner Scope? Dr Nancy's Sweetie
  2001-05-19 22:01 ` David C. Hoos, Sr.
@ 2001-05-20  3:15 ` Jeffrey Carter
  2001-05-20 12:29 ` Marc A. Criley
  2 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2001-05-20  3:15 UTC (permalink / raw)


Dr Nancy's Sweetie wrote:
> 
> I see two obvious solutions:
> 
>  1) The C-style solution, which is to move the stub into the package spec,
>     and thus have it accessable by every part of the package.  I don't
>     like this because one reason to use Ada is that you can have local
>     functions.
> 
>  2) The Pascal-style solution, which is to cram the whole function (and
>     it's really long, and there are several of them) into the declaration
>     section of the Put_Line() procedure.  I don't like this one, because
>     because it means that between the line "procedure Put_Line(...) is"
>     and the associated "begin", I would have almost 500 lines of code.

3) Make Put_Line separate, then make Wont_Work separate from it.

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus



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

* Re: Non-Stub In Inner Scope?
  2001-05-19 22:01 ` David C. Hoos, Sr.
  2001-05-19 23:08   ` Robert A Duff
@ 2001-05-20 10:50   ` RPrice9979
  1 sibling, 0 replies; 7+ messages in thread
From: RPrice9979 @ 2001-05-20 10:50 UTC (permalink / raw)


Another solution is to make procedure Put_Line a separate. In procedure
Put_Line make the declaration for Wont_Work just as written. 

This solution require 2 files instead of 1, but it does keep the abstraction
layer the same.

Ronald J. Price



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

* Re: Non-Stub In Inner Scope?
  2001-05-19 21:42 Non-Stub In Inner Scope? Dr Nancy's Sweetie
  2001-05-19 22:01 ` David C. Hoos, Sr.
  2001-05-20  3:15 ` Jeffrey Carter
@ 2001-05-20 12:29 ` Marc A. Criley
  2001-05-20 20:07   ` David C. Hoos, Sr.
  2 siblings, 1 reply; 7+ messages in thread
From: Marc A. Criley @ 2001-05-20 12:29 UTC (permalink / raw)


Dr Nancy's Sweetie wrote:
> 
> Both solutions also have the problem that I'd have to have the body of
> Wont_Work() in the example.adb file, making it impossible to do separate
> compilation.  There are several functions that go along with Wont_Work(),
> and they're pretty long.  They are debugged and stable at this point,
> which is why I wanted to move them out; the rest of the package is still
> in flux.  Recompiling that code over and over can consume a lot of time.

While it's been mentioned that moving "Wont_Work" out of the function
and into the package body has been suggested, you should know that if
you're using the GNAT Ada 95 compiler, the bodies of all of package's
"separates" are compiled when the package body is compiled, despite
their being in separate files.  Other compilers may well handle this
situation differently.

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



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

* Re: Non-Stub In Inner Scope?
  2001-05-20 12:29 ` Marc A. Criley
@ 2001-05-20 20:07   ` David C. Hoos, Sr.
  0 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos, Sr. @ 2001-05-20 20:07 UTC (permalink / raw)



"Marc A. Criley" <mcqada@earthlink.net> wrote in message
news:3B07AB9C.C02C5D56@earthlink.net...
> Dr Nancy's Sweetie wrote:
> >
> > Both solutions also have the problem that I'd have to have the body of
> > Wont_Work() in the example.adb file, making it impossible to do separate
> > compilation.  There are several functions that go along with
Wont_Work(),
> > and they're pretty long.  They are debugged and stable at this point,
> > which is why I wanted to move them out; the rest of the package is still
> > in flux.  Recompiling that code over and over can consume a lot of time.
>
> While it's been mentioned that moving "Wont_Work" out of the function
> and into the package body has been suggested, you should know that if
> you're using the GNAT Ada 95 compiler, the bodies of all of package's
> "separates" are compiled when the package body is compiled, despite
> their being in separate files.  Other compilers may well handle this
> situation differently.
>
True enough -- but you can still compile a separate sepearetely with GNAT,
even though other stubbed units may not be present, so this still permits
separate compilation with appropriate error messages, even though no
object file will be produced untill all spearates are present anc compile
correctly.





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

end of thread, other threads:[~2001-05-20 20:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-19 21:42 Non-Stub In Inner Scope? Dr Nancy's Sweetie
2001-05-19 22:01 ` David C. Hoos, Sr.
2001-05-19 23:08   ` Robert A Duff
2001-05-20 10:50   ` RPrice9979
2001-05-20  3:15 ` Jeffrey Carter
2001-05-20 12:29 ` Marc A. Criley
2001-05-20 20:07   ` David C. Hoos, Sr.

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