comp.lang.ada
 help / color / mirror / Atom feed
* Representation item appears too late
@ 2007-10-25 13:35 Ludovic Brenta
  2007-10-25 13:46 ` Lucretia
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ludovic Brenta @ 2007-10-25 13:35 UTC (permalink / raw)


Consider the following declarations:

package A is

   type Size is (Small, Large);

   type Foo is range 1 .. 8;

   type T is record
      A : Boolean;
      B : Boolean;
      C : Boolean;
      D : Size_Type;
      E : Foo;
   end record;

   procedure P (X : in T); -- a null procedure for the sake of example

end A;

with A;
package B is

   type T is new A.T;
   for T use record -- line 5
      A at 0 range 0 .. 0;
      B at 0 range 1 .. 1;
      C at 0 range 2 .. 2;
      D at 0 range 3 .. 3;
      E at 0 range 4 .. 7;
   end record;

end B;

Compiling B with GCC 4.1 I get:

gcc-4.1 -c -g -O2 -gnatafnoy -gnatVa -gnatwa -I- -gnatA /home/lbrenta/src/ada/b.ads
b.ads:5:04: representation item appears too late
b.ads:5:04: primitive operations already defined for "T"
gnatmake: "/home/lbrenta/src/ada/b.ads" compilation error

This also happens with GCC 4.2.

Of course, removing procedure A.P also removes the error but this is
not an option.

What should I do to specify a representation clause?  Do I have to
resort to declaring a mirror type in B?  Why?

Thanks for any advice.

-- 
Ludovic Brenta.



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

* Re: Representation item appears too late
  2007-10-25 13:35 Representation item appears too late Ludovic Brenta
@ 2007-10-25 13:46 ` Lucretia
  2007-10-25 15:41 ` Adam Beneschan
  2007-10-26  4:08 ` Vincent Marciante
  2 siblings, 0 replies; 6+ messages in thread
From: Lucretia @ 2007-10-25 13:46 UTC (permalink / raw)


On Oct 25, 2:35 pm, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Consider the following declarations:
>
> package A is
>
>    type Size is (Small, Large);
>
>    type Foo is range 1 .. 8;
>
>    type T is record
>       A : Boolean;
>       B : Boolean;
>       C : Boolean;
>       D : Size_Type;

Should be "Size"

>       E : Foo;
>    end record;
>
>    procedure P (X : in T); -- a null procedure for the sake of example
>
> end A;
>
> with A;
> package B is
>
>    type T is new A.T;

I didn't even know that this was possible!

>    for T use record -- line 5
>       A at 0 range 0 .. 0;
>       B at 0 range 1 .. 1;
>       C at 0 range 2 .. 2;
>       D at 0 range 3 .. 3;
>       E at 0 range 4 .. 7;
>    end record;
>
> end B;
>
> Compiling B with GCC 4.1 I get:
>
> gcc-4.1 -c -g -O2 -gnatafnoy -gnatVa -gnatwa -I- -gnatA /home/lbrenta/src/ada/b.ads
> b.ads:5:04: representation item appears too late
> b.ads:5:04: primitive operations already defined for "T"
> gnatmake: "/home/lbrenta/src/ada/b.ads" compilation error
>
> This also happens with GCC 4.2.
>
> Of course, removing procedure A.P also removes the error but this is
> not an option.
>
> What should I do to specify a representation clause?  Do I have to
> resort to declaring a mirror type in B?  Why?

I've always put the representation clauses with the types they refer
to.

Luke.





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

* Re: Representation item appears too late
  2007-10-25 13:35 Representation item appears too late Ludovic Brenta
  2007-10-25 13:46 ` Lucretia
@ 2007-10-25 15:41 ` Adam Beneschan
  2007-10-25 18:37   ` Ludovic Brenta
  2007-10-26  4:08 ` Vincent Marciante
  2 siblings, 1 reply; 6+ messages in thread
From: Adam Beneschan @ 2007-10-25 15:41 UTC (permalink / raw)


On Oct 25, 6:35 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Consider the following declarations:
>
> package A is
>
>    type Size is (Small, Large);
>
>    type Foo is range 1 .. 8;
>
>    type T is record
>       A : Boolean;
>       B : Boolean;
>       C : Boolean;
>       D : Size; -- corrected, was Size_Type;
>       E : Foo;
>    end record;
>
>    procedure P (X : in T); -- a null procedure for the sake of example
>
> end A;
>
> with A;
> package B is
>
>    type T is new A.T;
>    for T use record -- line 5
>       A at 0 range 0 .. 0;
>       B at 0 range 1 .. 1;
>       C at 0 range 2 .. 2;
>       D at 0 range 3 .. 3;
>       E at 0 range 4 .. 7;
>    end record;
>
> end B;
>
> Compiling B with GCC 4.1 I get:
>
> gcc-4.1 -c -g -O2 -gnatafnoy -gnatVa -gnatwa -I- -gnatA /home/lbrenta/src/ada/b.ads
> b.ads:5:04: representation item appears too late
> b.ads:5:04: primitive operations already defined for "T"
> gnatmake: "/home/lbrenta/src/ada/b.ads" compilation error
>
> This also happens with GCC 4.2.
>
> Of course, removing procedure A.P also removes the error but this is
> not an option.
>
> What should I do to specify a representation clause?  Do I have to
> resort to declaring a mirror type in B?  Why?

The error message you're getting isn't very helpful.  What you're
trying to do is explicitly forbidden by 13.1(10):

=================================================================
(10) For an untagged derived type, no type-related representation
items are allowed if the parent type is a by-reference type, or has
any user-defined primitive subprograms.

(AARM 10.b) Reason: ... The reason for forbidding type-related
representation items on untagged types with user-defined primitive
subprograms was to prevent implicit change of representation for type-
related aspects of representation upon calling inherited subprograms,
because such changes of representation are likely to be expensive at
run time. ...
=================================================================

> Thanks for any advice.

You could declare T in an inner package of A, then right after that
inner package say "subtype T is Inner.T;".  The result would be that P
would not be a primitive subprogram.  It also wouldn't be inherited
when B.T is declared---i.e. B.P would not exist unless you declare it
yourself.  That might work---but I don't know if there are any other
consequences elsewhere in your program to defining T in an inner
package.

Another possibility would be to put P in an inner package inside A,
which would again make it not primitive (and not inherited).  Of
course, that would require all the references to P elsewhere in the
program to change.  And you couldn't have a renaming of Inner.P
outside the inner package, because the renaming would become a
primitive subprogram of T and you'd end up with the same problem.

                        -- Adam




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

* Re: Representation item appears too late
  2007-10-25 15:41 ` Adam Beneschan
@ 2007-10-25 18:37   ` Ludovic Brenta
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Brenta @ 2007-10-25 18:37 UTC (permalink / raw)


Adam Beneschan writes:
> The error message you're getting isn't very helpful.  What you're
> =================================================================
> (10) For an untagged derived type, no type-related representation
> items are allowed if the parent type is a by-reference type, or has
> any user-defined primitive subprograms.
>
> (AARM 10.b) Reason: ... The reason for forbidding type-related
> representation items on untagged types with user-defined primitive
> subprograms was to prevent implicit change of representation for type-
> related aspects of representation upon calling inherited subprograms,
> because such changes of representation are likely to be expensive at
> run time. ...
> =================================================================

Ah, that's what I missed when I looked in the ARM.  I should have
spent five minutes more and I'm sure I'd have found it :/

Thanks a lot!

I'll apply the rep clause to the top-level type.  In this particular
case, artificially making the procedure not primitive is even uglier
(even though nothing depends on that procedure being primitive) as it
would introduce unnecessary entities in the package spec.

-- 
Ludovic Brenta.



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

* Re: Representation item appears too late
  2007-10-25 13:35 Representation item appears too late Ludovic Brenta
  2007-10-25 13:46 ` Lucretia
  2007-10-25 15:41 ` Adam Beneschan
@ 2007-10-26  4:08 ` Vincent Marciante
  2007-10-26  8:34   ` Ludovic Brenta
  2 siblings, 1 reply; 6+ messages in thread
From: Vincent Marciante @ 2007-10-26  4:08 UTC (permalink / raw)


Ludovic Brenta wrote:
> 
> Consider the following declarations:
> 
> package A is
> 
>    type Size is (Small, Large);
> 
>    type Foo is range 1 .. 8;
> 
>    type T is record
>       A : Boolean;
>       B : Boolean;
>       C : Boolean;
>       D : Size_Type;
>       E : Foo;
>    end record;
> 
>    procedure P (X : in T); -- a null procedure for the sake of example
> 
> end A;
> 
> with A;
> package B is
> 
>    type T is new A.T;
>    for T use record -- line 5
>       A at 0 range 0 .. 0;
>       B at 0 range 1 .. 1;
>       C at 0 range 2 .. 2;
>       D at 0 range 3 .. 3;
>       E at 0 range 4 .. 7;
>    end record;
> 
> end B;
> 
> Compiling B with GCC 4.1 I get:
> 
> gcc-4.1 -c -g -O2 -gnatafnoy -gnatVa -gnatwa -I- -gnatA /home/lbrenta/src/ada/b.ads
> b.ads:5:04: representation item appears too late
> b.ads:5:04: primitive operations already defined for "T"
> gnatmake: "/home/lbrenta/src/ada/b.ads" compilation error
> 
> This also happens with GCC 4.2.

How about:


package A is

   type Size is (Small, Large);

   type Foo is range 1 .. 8;

   package Base is
      type T is record
         A : Boolean;
         B : Boolean;
         C : Boolean;
         D : Size;
         E : Foo;
      end record;
   end Base; 

   type T is new Base.T;

   procedure P (X : in T); -- a null procedure for the sake of example

end A;

with A;
package B is

   type T is new A.Base.T;
   for T use record -- line 5
      A at 0 range 0 .. 0;
      B at 0 range 1 .. 1;
      C at 0 range 2 .. 2;
      D at 0 range 3 .. 3;
      E at 0 range 4 .. 7;
   end record;

end B;


Vinny


--




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

* Re: Representation item appears too late
  2007-10-26  4:08 ` Vincent Marciante
@ 2007-10-26  8:34   ` Ludovic Brenta
  0 siblings, 0 replies; 6+ messages in thread
From: Ludovic Brenta @ 2007-10-26  8:34 UTC (permalink / raw)


Vincent Marciante writes:
> How about:
>
> package A is
>
>    type Size is (Small, Large);
>
>    type Foo is range 1 .. 8;
>
>    package Base is
>       type T is record
[...]
>       end record;
>    end Base; 
>
>    type T is new Base.T;
>
>    procedure P (X : in T); -- a null procedure for the sake of example
>
> end A;

Yes, that makes P not primitive but it introduces two unnecessary
entities (Base and Base.T) in the spec of A and clutters it.  Not only
that but I'd also have to add comments explaining why I do things that
way: so that I can add a rep clause in an unrelated package.  As I
said, I think this would be even uglier than adding the rep clause
directly in A.

-- 
Ludovic Brenta.



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

end of thread, other threads:[~2007-10-26  8:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-25 13:35 Representation item appears too late Ludovic Brenta
2007-10-25 13:46 ` Lucretia
2007-10-25 15:41 ` Adam Beneschan
2007-10-25 18:37   ` Ludovic Brenta
2007-10-26  4:08 ` Vincent Marciante
2007-10-26  8:34   ` Ludovic Brenta

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