comp.lang.ada
 help / color / mirror / Atom feed
* type mismatches/access type
@ 2001-03-04 20:35 Frank
  2001-03-04 20:43 ` Additional info for the message above: for Linux/RedHat6.2/Gnat3.13 Frank
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Frank @ 2001-03-04 20:35 UTC (permalink / raw)


Hi!

I have downloaded the source code for the ADEPT projekt (on AdaPower
w-page).
There is a package  that is a part of the "jxtrans" program
in there that I get a compilation error on, code snippet (of what I believe
is
important :-) follows:
The compiler is very frustrated by the use of the "=" operator and

the error message is as follows:

gnatgcc -c -gnatf jxt_list.adb
jxt_list.adb:26:19: invalid operand types for operator "="
jxt_list.adb:26:19: left operand has type access to "Element_T'Class"
defined at jxt_list.ads:23
jxt_list.adb:26:19: right operand has an access type
jxt_list.adb:33:26: expected type "Element_p" defined at jxt_list.ads:21
jxt_list.adb:33:26: found type access to "Element_T'Class" defined at
jxt_list.ads:23
jxt_list.adb:34:26: expected type "Element_p" defined at jxt_list.ads:21
jxt_list.adb:34:26: found type access to "Element_T'Class" defined at
jxt_list.ads:23
jxt_list.adb:38:31: expected type "Element_p" defined at jx......
asf on several places.

I have tried to replace the use of "access Element_t'Class;"
in the package and used the "Element_p" instead. Then this package compiles,
but then another package depending on this one get in trouble instead.


Is there some way to convince the compiler that Element can be "null"?
or does anyone have a suggestion as to why I get this error; after all,
the package has compiled on Solaris...



spec part
....
...
   type Element_t is tagged private;
   type Element_p is access all Element_t'class;

   procedure Add (Element : access Element_t'Class;
                  List : List_p);
   procedure Remove (Element : access Element_t'Class);


body part:

package body JxT_List is

   ----------------------------
   -- Add                    --
   ----------------------------
   --  Public
   --  Adds an element to a list.
   --
   procedure Add (Element : access Element_t'Class;
                  List : List_p) is
   begin
      if (Element = null) then     <-----------------Compiler reports error
ln:26
         null;
      else
         if (Element.List /= null) then
            Remove (Element);
         end if;
         if (List.Num_Elems = 0) then
            List.Head := Element;  <--------------Compiler reports error
ln:33
            List.Tail := Element;
            Element.Next := null;
            Element.Prev := null;
         else
....
...
...





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

* Additional info for the message above: for Linux/RedHat6.2/Gnat3.13
  2001-03-04 20:35 type mismatches/access type Frank
@ 2001-03-04 20:43 ` Frank
  2001-03-07 21:55 ` Still open for suggestions :-) Frank
  2001-03-07 23:38 ` type mismatches/access type Mark Lundquist
  2 siblings, 0 replies; 5+ messages in thread
From: Frank @ 2001-03-04 20:43 UTC (permalink / raw)


Hi!

Question goes for:
Additional info for the message above: for Linux/RedHat6.2/Gnat3.13

Frank





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

* Still open for suggestions :-)
  2001-03-04 20:35 type mismatches/access type Frank
  2001-03-04 20:43 ` Additional info for the message above: for Linux/RedHat6.2/Gnat3.13 Frank
@ 2001-03-07 21:55 ` Frank
  2001-03-07 23:38 ` type mismatches/access type Mark Lundquist
  2 siblings, 0 replies; 5+ messages in thread
From: Frank @ 2001-03-07 21:55 UTC (permalink / raw)


Hi!

I'm still stuck on this issue. Have studied the
http://www.vaxxine.com/pegasoft/homes/11.html
but haven't found examples that quite fit my situation.

Now choose to supply the full source code for the headace.
Is there some compile options I must use? or could I have a invalid
installation??


Frank

package JxT_List is

   type List_t is tagged private;
   type List_p is access all List_t'class;

   type Element_t is tagged private;
   type Element_p is access all Element_t'class;

   procedure Add (Element : access Element_t'Class;
                  List : List_p);
   procedure Remove (Element : access Element_t'Class);

   function Get_First (List : List_p) return Element_p;
   function Get_Next (Element : access Element_t'Class) return Element_p;

   function Get_List (Element : access Element_t'Class) return List_p;

private

   --
   --  Doubly-linked...
   --
   type Element_t is tagged record
      Next : Element_p;
      Prev : Element_p;
      List : List_p;
   end record;

   --
   --  With head and tail pointers.  Non-circular.
   --
   type List_t is tagged record
      Head : Element_p := null;
      Tail : Element_p := null;
      Num_Elems : integer := 0;
   end record;

end JxT_List;

package body JxT_List is

   ----------------------------
   -- Add                    --
   ----------------------------
   --  Public
   --  Adds an element to a list.
   --
   procedure Add (Element : access Element_t'Class;
                  List : List_p) is
   begin
      if (Element = null) then
         null;
      else
         if (Element.List /= null) then
            Remove (Element);
         end if;
         if (List.Num_Elems = 0) then
            List.Head := Element;
            List.Tail := Element;
            Element.Next := null;
            Element.Prev := null;
         else
            List.Tail.Next := Element;
            Element.Next := null;
            Element.Prev := List.Tail;
            List.Tail := Element;
         end if;
         List.Num_Elems := List.Num_Elems + 1;
         Element.List := List;
      end if;
   end Add;

   ----------------------------
   -- Remove                 --
   ----------------------------
   --  Public
   --  Removes an element from it's list.
   --
   procedure Remove (Element : access Element_t'Class) is
      List : List_p;
   begin
      if Element = null then
         return;
      elsif Element.List = null then
         return;
      else  -- now do the real delete
         List := Element.List;
         if (List.Num_Elems = 1) then        -- only element
            List.Head := null;
            List.Tail := null;
         elsif (List.Head = Element) then    -- first element
            List.Head := Element.Next;
            List.Head.Prev := null;
         elsif (List.Tail = Element) then    -- last element
            List.Tail := Element.Prev;
            List.Tail.Next := null;
         else                                -- somewhere in middle
            Element.Prev.Next := Element.Next;
            Element.Next.Prev := Element.Prev;
         end if;
         List.Num_Elems := List.Num_Elems - 1;
         Element.Next := null;
         Element.Prev := null;
         Element.List := null;
      end if;
   end Remove;

   ----------------------------
   -- Get_Next               --
   ----------------------------
   --  Public
   --  Given an element, returns the next element in whatever
   --  list the element is in.
   --
   function Get_Next (Element : access Element_t'Class) return Element_p is
   begin
      if Element = null then
         return null;
      else
         return Element.Next;
      end if;
   end Get_Next;

   ----------------------------
   -- Get_First              --
   ----------------------------
   --  Public
   --  Returns pntr to first element in a list
   --
   function Get_First (List : List_p) return Element_p is
   begin
      return List.Head;
   end Get_First;

   ----------------------------
   -- Get_List               --
   ----------------------------
   --  Public
   --  Returns pntr to List that this element is in;
   --      null if not in a list.
   --
   function Get_List (Element : access Element_t'Class) return List_p is
   begin
      return Element.List;
   end Get_List;

end JxT_List;






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

* Re: type mismatches/access type
  2001-03-04 20:35 type mismatches/access type Frank
  2001-03-04 20:43 ` Additional info for the message above: for Linux/RedHat6.2/Gnat3.13 Frank
  2001-03-07 21:55 ` Still open for suggestions :-) Frank
@ 2001-03-07 23:38 ` Mark Lundquist
  2001-03-08  6:24   ` Frank
  2 siblings, 1 reply; 5+ messages in thread
From: Mark Lundquist @ 2001-03-07 23:38 UTC (permalink / raw)



Frank <franjoe@frisurf.no> wrote in message
news:wKxo6.7148$t21.173574@news3.oke.nextra.no...
> Hi!
>
> I have downloaded the source code for the ADEPT projekt (on AdaPower
> w-page).
> There is a package  that is a part of the "jxtrans" program
> in there that I get a compilation error on, code snippet (of what I
believe
> is
> important :-) follows:
> The compiler is very frustrated by the use of the "=" operator and
>

Yes, and it doesn't like assignment either (and rightly so).

[...]
>
> Is there some way to convince the compiler that Element can be "null"?

Well, that's just it... Element can't be null!  :-)  Null does not exist for
anonymous access types, such as defined by an access parameter.

First of all: delete the if statements that deal with "if Element = null".
They're meaningless and illegal, and there's no way to make them meaningful
or legal, and they wouldn't do you any good if there were.  The call to the
subprogram involves an implicit conversion from the type of the actual
parameter value to the anonymous type of the access parameter, so if you
tried to pass a null access value as the actual parameter, the conversion
will raise Constraint_Error (since null does not exist for the type you're
converting to.

Second: look at the places where you are assigning the value of an access
parameter to an object of a named access type (I think something like
"List.Head := Element" in your example).  You need a conversion to make this
legal, e.g.

    List.Head := Element_P (Element);

or whatever.

> after all,the package has compiled on Solaris...

Thirdly: if you mean that you compiled it successfully, then take that
compiler and throw it away!

Fourthly: get rid of those annoying '('...')' around the expressions in the
"if" statements.


Hope this helps!

Mark Lundquist
Rational Software






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

* Re: type mismatches/access type
  2001-03-07 23:38 ` type mismatches/access type Mark Lundquist
@ 2001-03-08  6:24   ` Frank
  0 siblings, 0 replies; 5+ messages in thread
From: Frank @ 2001-03-08  6:24 UTC (permalink / raw)


Hi!

Thanks.
Although the download page said that it was untested, I didn't realise that
it was quite that untested :-)
and assumed that ADEPT had managed to compile it on Solaris (I have not).
I shall try your suggestions and see if things start working :-)

Frank





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

end of thread, other threads:[~2001-03-08  6:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-04 20:35 type mismatches/access type Frank
2001-03-04 20:43 ` Additional info for the message above: for Linux/RedHat6.2/Gnat3.13 Frank
2001-03-07 21:55 ` Still open for suggestions :-) Frank
2001-03-07 23:38 ` type mismatches/access type Mark Lundquist
2001-03-08  6:24   ` Frank

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