comp.lang.ada
 help / color / mirror / Atom feed
* Another question on class constructor
@ 2011-11-08  2:27 Rego, P.
  2011-11-08  4:32 ` Randy Brukardt
  0 siblings, 1 reply; 6+ messages in thread
From: Rego, P. @ 2011-11-08  2:27 UTC (permalink / raw)


I have a class defined as:

   type Test_Class is tagged limited
      record
         Info    : Integer;
         Value   : Float;
         Primary : Primary_Task (Test_Class'Access);
      end record;

I need build a one-step constructor for my class in the form

   function Construct (T : access Test_Class) return Test_Class_Ptr is
   begin
      return new Test_Class'(Info => T.Info + 1,
                             Value => 0.0,
                             Primary => [WHAT I WANNA KNOW]);
   end Construct;

Currently my code is:

-- test_pkg.ads
package Test_Pkg is
   type Test_Class;
   type Test_Class_Ptr is access all Test_Class;

   task type Primary_Task (This_Test : access Test_Class) is
      pragma Storage_Size (1000);
   end Primary_Task;

   type Test_Class is tagged limited
      record
         Info    : Integer;
         Value   : Float;
         Primary : Primary_Task (Test_Class'Access);
      end record;

   function Construct (T : access Test_Class) return Test_Class_Ptr;
end Test_Pkg;

-- test_pkg.adb
with Text_IO; use Text_IO;
package body Test_Pkg is
   [...]

   function Construct (T : access Test_Class) return Test_Class_Ptr is
      T_Ptr : constant Test_Class_Ptr := new Test_Class;
   begin
      T_Ptr.Info := T.Info + 1;
      T_Ptr.Value := 0.0;
      return T_Ptr;
   end Construct;
end Test_Pkg;

So, how can I code it? What should I put in Primary => [...] code? Should I change the definition of Primary : Primary_Task (Test_Class'Access); in Test_Class definition? Thanks.



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

* Re: Another question on class constructor
  2011-11-08  2:27 Another question on class constructor Rego, P.
@ 2011-11-08  4:32 ` Randy Brukardt
  2011-11-09  0:40   ` Rego, P.
  0 siblings, 1 reply; 6+ messages in thread
From: Randy Brukardt @ 2011-11-08  4:32 UTC (permalink / raw)


"Rego, P." <pvrego@gmail.com> wrote in message 
news:19338900.553.1320719246503.JavaMail.geo-discussion-forums@yqpp12...
>I have a class defined as:
>
>   type Test_Class is tagged limited
>      record
>         Info    : Integer;
>         Value   : Float;
>         Primary : Primary_Task (Test_Class'Access);
>      end record;
>
> I need build a one-step constructor for my class in the form
>
>   function Construct (T : access Test_Class) return Test_Class_Ptr is
>   begin
>      return new Test_Class'(Info => T.Info + 1,
>                             Value => 0.0,
>                             Primary => [WHAT I WANNA KNOW]);
>   end Construct;

In Ada 2005 or later, use "<>" to default initialize a component in an 
aggregate (which is the only thing you can do with a task). In Ada 95, you 
are SOL. (Ask someone else what that means if you don't know. ;-)

function Construct (T : access Test_Class) return Test_Class_Ptr is
begin
     return new Test_Class'(Info => T.Info + 1,
                           Value => 0.0,
                           Primary => <>);
 end Construct;

                                  Randy.






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

* Re: Another question on class constructor
  2011-11-08  4:32 ` Randy Brukardt
@ 2011-11-09  0:40   ` Rego, P.
  2011-11-09  1:08     ` Rego, P.
  2011-11-09  8:30     ` Simon Wright
  0 siblings, 2 replies; 6+ messages in thread
From: Rego, P. @ 2011-11-09  0:40 UTC (permalink / raw)


I had tried it before, but keep returning a compilation error:
    raised TYPES.UNRECOVERABLE_ERROR : comperr.adb:423
    gnatmake: "c:\tst\test_pkg_rev618.adb" compilation error
    [2011-11-08 22:15:32] process exited with status 4 (elapsed time: 00.20s)
What should it be?

Actually, I got a suggestion looked like this in some posts ago and I was trying to follow it. Now I realize that I was not making wrong (I thought this error message was due to some mistake in my code). And I guess this is a GNAT bug from GNAT GPL 2011:

c:\tst>gnatmake -gnat12 test_pkg.adb
gcc -c -gnat12 test_pkg.adb
+===========================GNAT BUG DETECTED==============================+
| GPL 2011 (20110428) (i686-pc-mingw32) GCC error:                         |
| in create_tmp_var, at gimplify.c:505                                     |
| Error detected around test_pkg.adb:20:29                          |
| Please submit a bug report by email to report@adacore.com.               |
| GAP members can alternatively use GNAT Tracker:                          |
| http://www.adacore.com/ section 'send a report'.                         |
| See gnatinfo.txt for full info on procedure for submitting bugs.         |
| Use a subject line meaningful to you and us to track the bug.            |
| Include the entire contents of this bug box in the report.               |
| Include the exact gcc or gnatmake command that you entered.              |
| Also include sources listed below in gnatchop format                     |
| (concatenated together with no headers between files).                   |
| Use plain ASCII or MIME attachment.                                      |
+==========================================================================+

Please include these source files with error report
Note that list may not be accurate in some cases,
so please double check that the problem can still
be reproduced with the set of files listed.
Consider also -gnatd.n switch (see debug.adb).

test_pkg.adb
test_pkg.ads


raised TYPES.UNRECOVERABLE_ERROR : comperr.adb:423
gnatmake: "test_pkg.adb" compilation error

--
and if I don't use the switch -gnat12 the error message is the same.



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

* Re: Another question on class constructor
  2011-11-09  0:40   ` Rego, P.
@ 2011-11-09  1:08     ` Rego, P.
  2011-11-09  8:30     ` Simon Wright
  1 sibling, 0 replies; 6+ messages in thread
From: Rego, P. @ 2011-11-09  1:08 UTC (permalink / raw)


Randy, thank you for your suggestion.



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

* Re: Another question on class constructor
  2011-11-09  0:40   ` Rego, P.
  2011-11-09  1:08     ` Rego, P.
@ 2011-11-09  8:30     ` Simon Wright
  2011-11-10  1:25       ` Rego, P.
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Wright @ 2011-11-09  8:30 UTC (permalink / raw)


"Rego, P." <pvrego@gmail.com> writes:

> Actually, I got a suggestion looked like this in some posts ago and I
> was trying to follow it. Now I realize that I was not making wrong (I
> thought this error message was due to some mistake in my code). And I
> guess this is a GNAT bug from GNAT GPL 2011:
>
> c:\tst>gnatmake -gnat12 test_pkg.adb
> gcc -c -gnat12 test_pkg.adb
> +===========================GNAT BUG DETECTED==============================+
> | GPL 2011 (20110428) (i686-pc-mingw32) GCC error:                         |
> | in create_tmp_var, at gimplify.c:505                                     |
> | Error detected around test_pkg.adb:20:29                          |
> | Please submit a bug report by email to report@adacore.com.               |

Have you done that?

I get the same here, also with GCC 4.6.0, but not with 4.7 [180524] so
_may_ already be fixed in AdaCore's sources.

When you see a bug box like this, it's definitely a compiler error;
whether it's because it doesn't handle your legal code, or because it
fails to detect your illegal code and give a proper error report, it's
still wrong!



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

* Re: Another question on class constructor
  2011-11-09  8:30     ` Simon Wright
@ 2011-11-10  1:25       ` Rego, P.
  0 siblings, 0 replies; 6+ messages in thread
From: Rego, P. @ 2011-11-10  1:25 UTC (permalink / raw)


> Have you done that?
Yes.

> I get the same here, also with GCC 4.6.0, but not with 4.7 [180524] so
> _may_ already be fixed in AdaCore's sources.
> 
> When you see a bug box like this, it's definitely a compiler error;
> whether it's because it doesn't handle your legal code, or because it
> fails to detect your illegal code and give a proper error report, it's
> still wrong!
I agree.



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

end of thread, other threads:[~2011-11-10  1:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-08  2:27 Another question on class constructor Rego, P.
2011-11-08  4:32 ` Randy Brukardt
2011-11-09  0:40   ` Rego, P.
2011-11-09  1:08     ` Rego, P.
2011-11-09  8:30     ` Simon Wright
2011-11-10  1:25       ` Rego, P.

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