comp.lang.ada
 help / color / mirror / Atom feed
* Splitting packages  in per-procedure separate files
@ 2007-02-10 16:23 Francesco Bochicchio
  2007-02-10 17:50 ` Stephen Sangwine
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Francesco Bochicchio @ 2007-02-10 16:23 UTC (permalink / raw)


Hi all,

due to coding standards which  were not enforced when someone else coded,
I now have to split the packages of a 20000 LOC ADA program, putting a
single procedure per file (using the separate clause).

While this is not a very big work. it would be nice t find some tool to
help in this task.

Alternatively, I was tinking to prepare some script myself (Python + some
parser library ). In this case, it would help to have  ADA grammar rules
written in yacc-style or similar. This could also be useful in similar
situation in the future.

Any help/pointer is appreciated. Thakns in advance.

Ciao
-----
FB




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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 16:23 Splitting packages in per-procedure separate files Francesco Bochicchio
@ 2007-02-10 17:50 ` Stephen Sangwine
  2007-02-10 18:36   ` Anh Vo
  2007-02-10 19:36   ` Jeffrey R. Carter
  2007-02-10 18:49 ` Simon Wright
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 14+ messages in thread
From: Stephen Sangwine @ 2007-02-10 17:50 UTC (permalink / raw)


On 2007-02-10 16:23:12 +0000, Francesco Bochicchio <bockman@virgilio.it> said:

> Hi all,
> 
> due to coding standards which  were not enforced when someone else coded,
> I now have to split the packages of a 20000 LOC ADA program, putting a
> single procedure per file (using the separate clause).

You can only put procedures which are declared immediately within the
declarative part of a compilation unit into a separate file.
(LRM 95 10.1.3(13)).

20,000 LOC is quite a large program. If it has all the procedures declared
immediately within the main program declarative part that would be quite an
un-Ada way to have structured the code.

Is it really written like that?

Steve

> While this is not a very big work. it would be nice t find some tool to
> help in this task.
> 
> Alternatively, I was tinking to prepare some script myself (Python + some
> parser library ). In this case, it would help to have  ADA grammar rules
> written in yacc-style or similar. This could also be useful in similar
> situation in the future.
> 
> Any help/pointer is appreciated. Thakns in advance.
> 
> Ciao
> -----
> FB





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

* Re: Splitting packages in per-procedure separate files
  2007-02-10 17:50 ` Stephen Sangwine
@ 2007-02-10 18:36   ` Anh Vo
  2007-02-10 19:36   ` Jeffrey R. Carter
  1 sibling, 0 replies; 14+ messages in thread
From: Anh Vo @ 2007-02-10 18:36 UTC (permalink / raw)


On Feb 10, 9:50 am, Stephen Sangwine <s...@essex.ac.uk> wrote:
> On 2007-02-10 16:23:12 +0000, Francesco Bochicchio <bock...@virgilio.it> said:
>
> > Hi all,
>
> > due to coding standards which  were not enforced when someone else coded,
> > I now have to split the packages of a 20000 LOC ADA program, putting a
> > single procedure per file (using the separate clause).
>
> You can only put procedures which are declared immediately within the
> declarative part of a compilation unit into a separate file.
> (LRM 95 10.1.3(13)).
>
> 20,000 LOC is quite a large program. If it has all the procedures declared
> immediately within the main program declarative part that would be quite an
> un-Ada way to have structured the code.
>
> Is it really written like that?

I never even heard a procedure half of this size. This triggers my
curiosity to know more details about it.

AV




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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 16:23 Splitting packages in per-procedure separate files Francesco Bochicchio
  2007-02-10 17:50 ` Stephen Sangwine
@ 2007-02-10 18:49 ` Simon Wright
  2007-02-11 12:20   ` Francesco Bochicchio
  2007-02-12  9:13   ` Jean-Pierre Rosen
  2007-02-10 19:33 ` Jeffrey R. Carter
  2007-02-11 13:45 ` Jeffrey Creem
  3 siblings, 2 replies; 14+ messages in thread
From: Simon Wright @ 2007-02-10 18:49 UTC (permalink / raw)


Francesco Bochicchio <bockman@virgilio.it> writes:

> due to coding standards which were not enforced when someone else
> coded, I now have to split the packages of a 20000 LOC ADA program,
> putting a single procedure per file (using the separate clause).
>
> While this is not a very big work. it would be nice t find some tool
> to help in this task.
>
> Alternatively, I was tinking to prepare some script myself (Python +
> some parser library ). In this case, it would help to have ADA
> grammar rules written in yacc-style or similar. This could also be
> useful in similar situation in the future.

You might consider an ASIS-based tool.

I had thought that Adalog (http://www.adalog.fr/) might have already
done it, but it seems not (worth a look, though; AdaSubst is the tool
I was thinking of).

There are (at least) 2 implementations of ASIS -> XML tools.  I would
recommend my own
(http://gnat-asis.sourceforge.net/pmwiki.php/Main/ASIS2XML) but you
probably want to retain comments, so you might find Marc Criley's
(http://www.mckae.com/avatox.html) more appropriate.

Marc says

  "Given that the Avatox XML representation of the source code
  comprehensively represents the content and layout of the source
  code, there's nothing stopping one from developing a utility to
  reconstitute the Ada source from the XML.

  "Given that, XSLT transformations become available to modify the
  Avatox XML to produce a modified version of the original program."

and of course you need a good grasp of XSLT (probably) and a fair
amount of enthusiasm to contemplate doing the first part!



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 16:23 Splitting packages in per-procedure separate files Francesco Bochicchio
  2007-02-10 17:50 ` Stephen Sangwine
  2007-02-10 18:49 ` Simon Wright
@ 2007-02-10 19:33 ` Jeffrey R. Carter
  2007-02-11 13:45 ` Jeffrey Creem
  3 siblings, 0 replies; 14+ messages in thread
From: Jeffrey R. Carter @ 2007-02-10 19:33 UTC (permalink / raw)


Francesco Bochicchio wrote:
> 
> due to coding standards which  were not enforced when someone else coded,
> I now have to split the packages of a 20000 LOC ADA program, putting a
> single procedure per file (using the separate clause).
> 
> While this is not a very big work. it would be nice t find some tool to
> help in this task.

The only tool I've encountered that does this is Apex. It's probably not 
an option for your problem.

-- 
Jeff Carter
"C's solution to this [variable-sized array parameters] has real 
problems, and people who are complaining about safety definitely have a 
point."
Dennis Ritchie
25



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 17:50 ` Stephen Sangwine
  2007-02-10 18:36   ` Anh Vo
@ 2007-02-10 19:36   ` Jeffrey R. Carter
  2007-02-11 12:09     ` Francesco Bochicchio
  1 sibling, 1 reply; 14+ messages in thread
From: Jeffrey R. Carter @ 2007-02-10 19:36 UTC (permalink / raw)


Stephen Sangwine wrote:
> On 2007-02-10 16:23:12 +0000, Francesco Bochicchio <bockman@virgilio.it> 
> said:
> 
>> due to coding standards which  were not enforced when someone else coded,
>> I now have to split the packages of a 20000 LOC ADA program, putting a
>> single procedure per file (using the separate clause).
> 
> 20,000 LOC is quite a large program. If it has all the procedures declared
> immediately within the main program declarative part that would be quite an
> un-Ada way to have structured the code.
> 
> Is it really written like that?

He said "/packages/ of a 20000 LOC ADA [sic] program [emphasis added]", 
so clearly it's not all in the main procedure.

-- 
Jeff Carter
"C's solution to this [variable-sized array parameters] has real 
problems, and people who are complaining about safety definitely have a 
point."
Dennis Ritchie
25



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 19:36   ` Jeffrey R. Carter
@ 2007-02-11 12:09     ` Francesco Bochicchio
  2007-02-11 14:08       ` Markus E Leypold
                         ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Francesco Bochicchio @ 2007-02-11 12:09 UTC (permalink / raw)


Il Sat, 10 Feb 2007 19:36:09 +0000, Jeffrey R. Carter ha scritto:

> Stephen Sangwine wrote:
>> On 2007-02-10 16:23:12 +0000, Francesco Bochicchio <bockman@virgilio.it> 
>> said:
>> 
>>> due to coding standards which  were not enforced when someone else coded,
>>> I now have to split the packages of a 20000 LOC ADA program, putting a
>>> single procedure per file (using the separate clause).
>> 
>> 20,000 LOC is quite a large program. If it has all the procedures declared
>> immediately within the main program declarative part that would be quite an
>> un-Ada way to have structured the code.
>> 
>> Is it really written like that?
> 
> He said "/packages/ of a 20000 LOC ADA [sic] program [emphasis added]", 
> so clearly it's not all in the main procedure.

Right.

Maybe the term program was misleading. What I have is an
application consisting of a dozen different packages. Now the standard
mandates:

- one name_package.ads for package public declarations
- one name_package.adb for package private declarations (including
separate declarations for all procedures)
- one name_package-name_procedure.adb for each procedure in the package

Some of the coders have actually followed the standards, some have not,
putting all the procedure code inside the name_package.adb file. Now I
have to split these files ( about half of the packages, so probably 10000
line of codes, not the 20000 initially stated ).

This could be done by hand in at most a (very boring) week (but I'd say
three days could be enough), so I can't spend too much effort in
automating this task, except for: 
a) preparing for future similar activities 
b) having sligtly more fun.

Thanks to all the posters that answered. 

 Ciao
------
FB




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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 18:49 ` Simon Wright
@ 2007-02-11 12:20   ` Francesco Bochicchio
  2007-02-12  9:13   ` Jean-Pierre Rosen
  1 sibling, 0 replies; 14+ messages in thread
From: Francesco Bochicchio @ 2007-02-11 12:20 UTC (permalink / raw)


Il Sat, 10 Feb 2007 18:49:22 +0000, Simon Wright ha scritto:

> Francesco Bochicchio <bockman@virgilio.it> writes:
> 
>> due to coding standards which were not enforced when someone else
>> coded, I now have to split the packages of a 20000 LOC ADA program,
>> putting a single procedure per file (using the separate clause).
>>
>> While this is not a very big work. it would be nice t find some tool
>> to help in this task.
>>
>> Alternatively, I was tinking to prepare some script myself (Python +
>> some parser library ). In this case, it would help to have ADA
>> grammar rules written in yacc-style or similar. This could also be
>> useful in similar situation in the future.
> 
> You might consider an ASIS-based tool.
> 
> I had thought that Adalog (http://www.adalog.fr/) might have already
> done it, but it seems not (worth a look, though; AdaSubst is the tool
> I was thinking of).
> 
> There are (at least) 2 implementations of ASIS -> XML tools.  I would
> recommend my own
> (http://gnat-asis.sourceforge.net/pmwiki.php/Main/ASIS2XML) but you
> probably want to retain comments, so you might find Marc Criley's
> (http://www.mckae.com/avatox.html) more appropriate.
> 
> Marc says
> 
>   "Given that the Avatox XML representation of the source code
>   comprehensively represents the content and layout of the source
>   code, there's nothing stopping one from developing a utility to
>   reconstitute the Ada source from the XML.
> 
>   "Given that, XSLT transformations become available to modify the
>   Avatox XML to produce a modified version of the original program."
> 
> and of course you need a good grasp of XSLT (probably) and a fair
> amount of enthusiasm to contemplate doing the first part!

The problem is that I'm not very good at XML-related stuff and I have a
short time for the task, so if I can't  find  a quick slution I'll end
doing it by hand.

The links where interesting anyway, and the knowledge that exists tools
that convert ADA code in XML structure may come hany in the future.

Ciao & Thanks
------------
FB



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 16:23 Splitting packages in per-procedure separate files Francesco Bochicchio
                   ` (2 preceding siblings ...)
  2007-02-10 19:33 ` Jeffrey R. Carter
@ 2007-02-11 13:45 ` Jeffrey Creem
  3 siblings, 0 replies; 14+ messages in thread
From: Jeffrey Creem @ 2007-02-11 13:45 UTC (permalink / raw)


Francesco Bochicchio wrote:
> Hi all,
> 
> due to coding standards which  were not enforced when someone else coded,
> I now have to split the packages of a 20000 LOC ADA program, putting a
> single procedure per file (using the separate clause).
> 
> While this is not a very big work. it would be nice t find some tool to
> help in this task.
> 
> Alternatively, I was tinking to prepare some script myself (Python + some
> parser library ). In this case, it would help to have  ADA grammar rules
> written in yacc-style or similar. This could also be useful in similar
> situation in the future.

I'm not sure that this got posted

http://www.adaic.org/standards/95lrm/grammar9x.y

Used to be easy to find the YACC Ada 95 Grammar but there are so many 
dead links for it now it certainly clouds things a bit. I am not even 
sure this is the "best" one.



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-11 12:09     ` Francesco Bochicchio
@ 2007-02-11 14:08       ` Markus E Leypold
  2007-02-11 19:29       ` Gautier
  2007-02-12 10:45       ` Stephen Leake
  2 siblings, 0 replies; 14+ messages in thread
From: Markus E Leypold @ 2007-02-11 14:08 UTC (permalink / raw)



Francesco Bochicchio <bockman@virgilio.it> writes:

> This could be done by hand in at most a (very boring) week (but I'd say
> three days could be enough), so I can't spend too much effort in
> automating this task, except for: 
> a) preparing for future similar activities 
> b) having sligtly more fun.

Since you will b just doing it once: You could use awk (or perl) ans
just do heuristic pattern matching on the procedure headers to split
the packages in question. Those cases that won't yield to the approach
you could correct manually.

Regards -- Markus




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

* Re: Splitting packages  in per-procedure separate files
  2007-02-11 12:09     ` Francesco Bochicchio
  2007-02-11 14:08       ` Markus E Leypold
@ 2007-02-11 19:29       ` Gautier
  2007-02-12 10:45       ` Stephen Leake
  2 siblings, 0 replies; 14+ messages in thread
From: Gautier @ 2007-02-11 19:29 UTC (permalink / raw)


Francesco Bochicchio:

> Maybe the term program was misleading. What I have is an
> application consisting of a dozen different packages. Now the standard
> mandates:
> 
> - one name_package.ads for package public declarations
> - one name_package.adb for package private declarations (including
> separate declarations for all procedures)
> - one name_package-name_procedure.adb for each procedure in the package
> 
> Some of the coders have actually followed the standards, some have not,
> putting all the procedure code inside the name_package.adb file. Now I
> have to split these files ( about half of the packages, so probably 10000
> line of codes, not the 20000 initially stated ).
> 
> This could be done by hand in at most a (very boring) week (but I'd say
> three days could be enough), so I can't spend too much effort in
> automating this task, except for: 
> a) preparing for future similar activities 
> b) having sligtly more fun.
> 
> Thanks to all the posters that answered. 
> 
>  Ciao
> ------
> FB

At least the task of putting your separate procedures into files can be done 
automatically by GNAT. Say I modify (manually or automatically) a package to 
meet the standard you mention (modifications with "**"):

--8<-----------8<-----------8<---sep.txt-8<---------
package A is
   procedure B1;
   procedure B2;
end A;
package body A is
   procedure B1 is separate; -- ** line added **
   procedure B2 is separate; -- ** line added **
end A; -- ** line added **
separate(A) -- ** line added **
   procedure B1 is
   begin
     null;
   end B1;
separate(A) -- ** line added **
   procedure B2 is
   begin
     null;
   end B2;
-- end A; -- ** line commented out **
--8<-----------8<-----------8<-----------8<---------

Then gnatchop will do the following:
gnatchop sep.txt
splitting sep.txt into:
    a.ads
    a.adb
    a~b1.adb
    a~b2.adb

Then, you just need to rename your files with '-' instead of '~'.
HTH
______________________________________________________________
Gautier         -- http://www.mysunrise.ch/users/gdm/index.htm
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-10 18:49 ` Simon Wright
  2007-02-11 12:20   ` Francesco Bochicchio
@ 2007-02-12  9:13   ` Jean-Pierre Rosen
  1 sibling, 0 replies; 14+ messages in thread
From: Jean-Pierre Rosen @ 2007-02-12  9:13 UTC (permalink / raw)


Simon Wright a �crit :

> I had thought that Adalog (http://www.adalog.fr/) might have already
> done it, but it seems not (worth a look, though; AdaSubst is the tool
> I was thinking of).
> 
Actually, AdaSubst is a tool for a different purpose, typically when 
refactoring an old application. You declare that "procedure P that used 
to be in package Pack is now called A_Better_Name in package P.Child", 
and then AdaSubst will update all modules that used the package.

-- 
---------------------------------------------------------
            J-P. Rosen (rosen@adalog.fr)
Visit Adalog's web site at http://www.adalog.fr



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-11 12:09     ` Francesco Bochicchio
  2007-02-11 14:08       ` Markus E Leypold
  2007-02-11 19:29       ` Gautier
@ 2007-02-12 10:45       ` Stephen Leake
  2007-02-12 18:42         ` Francesco Bochicchio
  2 siblings, 1 reply; 14+ messages in thread
From: Stephen Leake @ 2007-02-12 10:45 UTC (permalink / raw)


Francesco Bochicchio <bockman@virgilio.it> writes:

> What I have is an application consisting of a dozen different
> packages. Now the standard mandates:
>
> - one name_package.ads for package public declarations
> - one name_package.adb for package private declarations (including
> separate declarations for all procedures)
> - one name_package-name_procedure.adb for each procedure in the package
>
> Some of the coders have actually followed the standards, some have not,
> putting all the procedure code inside the name_package.adb file. Now I
> have to split these files ( about half of the packages, so probably 10000
> line of codes, not the 20000 initially stated ).

In general, I approve of organizations enforcing coding standards;
they increase overall productivity. 

However, in this situation it's appropriate to consider whether this
coding standard should be changed instead.

If the process you are supposed to be using doesn't actually increase
productivity, or your bottom line, you should change the process in a
way that does. That is _required_ by CMMI, and definitely in the
spirit of ISO 9001.

What is the rationale for putting _every_ procedure in a separate
file?

Why do some coders choose to not follow the standard?

I have very few separate procedures in my applications. I had more in
Ada 83 code, but child packages are in general a better solution to
organizing code.

-- 
-- Stephe



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

* Re: Splitting packages  in per-procedure separate files
  2007-02-12 10:45       ` Stephen Leake
@ 2007-02-12 18:42         ` Francesco Bochicchio
  0 siblings, 0 replies; 14+ messages in thread
From: Francesco Bochicchio @ 2007-02-12 18:42 UTC (permalink / raw)


Il Mon, 12 Feb 2007 05:45:51 -0500, Stephen Leake ha scritto:

> Francesco Bochicchio <bockman@virgilio.it> writes:
> 
>> What I have is an application consisting of a dozen different
>> packages. Now the standard mandates:
>>
>> - one name_package.ads for package public declarations
>> - one name_package.adb for package private declarations (including
>> separate declarations for all procedures)
>> - one name_package-name_procedure.adb for each procedure in the package
>>
>> Some of the coders have actually followed the standards, some have not,
>> putting all the procedure code inside the name_package.adb file. Now I
>> have to split these files ( about half of the packages, so probably 10000
>> line of codes, not the 20000 initially stated ).
> 
> In general, I approve of organizations enforcing coding standards;
> they increase overall productivity. 
> 
> However, in this situation it's appropriate to consider whether this
> coding standard should be changed instead.

I agree. Unfortunately our client does not - at least on this specific
issue (they have relaxed other standards ... ).

> ...
 
> What is the rationale for putting _every_ procedure in a separate file?
> 

In theory, for readability. In theory. In my experience, I found that 
the code readability  depends on the IDE you are using. With
simple editors (say emacs or UltraEdit) I feel more comfortable to have a
whole package in a single file. With complete IDE (say GPS or AdaMulti) it
does not matter much one way or the other, since the file structure is
hidden behind the project structure.
Anyway I am not in the position to cange the standards ...

> Why do some coders choose to not follow the standard?
> 

It happens in messy projects, and the one in question has been _very_
messy ...

Ciao
------
FB



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

end of thread, other threads:[~2007-02-12 18:42 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-10 16:23 Splitting packages in per-procedure separate files Francesco Bochicchio
2007-02-10 17:50 ` Stephen Sangwine
2007-02-10 18:36   ` Anh Vo
2007-02-10 19:36   ` Jeffrey R. Carter
2007-02-11 12:09     ` Francesco Bochicchio
2007-02-11 14:08       ` Markus E Leypold
2007-02-11 19:29       ` Gautier
2007-02-12 10:45       ` Stephen Leake
2007-02-12 18:42         ` Francesco Bochicchio
2007-02-10 18:49 ` Simon Wright
2007-02-11 12:20   ` Francesco Bochicchio
2007-02-12  9:13   ` Jean-Pierre Rosen
2007-02-10 19:33 ` Jeffrey R. Carter
2007-02-11 13:45 ` Jeffrey Creem

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