comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: Porting from Modula-2 to Ada
Date: Sat, 19 Oct 2002 13:30:04 GMT
Date: 2002-10-19T13:30:04+00:00	[thread overview]
Message-ID: <v7ds9.9686$qM2.3081@sccrnsc02> (raw)
In-Reply-To: 3DAFC542.152C0EE0@lml.ls.fi.upm.es

"Manuel Collado" <m.collado@lml.ls.fi.upm.es> wrote in message
news:3DAFC542.152C0EE0@lml.ls.fi.upm.es...
[snip]
> So far, my only porting scheme is to replace ARRAY OF BYTE parameters by
> the pair (address, size), as follows:
>
>    procedure Xxx (Raw_Address: System.Address; Raw_Size: Integer) ...
>
>    Num: Integer;
>    ...
>       Xxx (Num'Address, Num'Size);
>    ...
>
> But this requires recoding every call to the procedure. Is there another
> way to pass raw data without having to recode every call?

First: I have translated a significant amount of Pascal code to Ada.  From
this experience I would recommend producing a tool to do most of the
translation.

Making the mapping you just described should be fairly easy for such a tool.

The only alternate for this implementation that comes to mind is to create
arrays of bytes that alias each structure and passing the alias to Xxx.  For
example:

with Interfaces; use interfaces;
with Ada.Text_Io;

procedure testconv is

  type byte_array is array( Natural range <> ) of Unsigned_8;

  type data_rec is
    record
      field_1 : Integer;
      field_2 : String( 1 .. 8 );
    end record;

  procedure Xxx( raw : in out byte_array ) is
  begin
    raw( 0 ) := 2;
    raw( 1 ) := 0;
    raw( 2 ) := 0;
    raw( 3 ) := 0;
  end Xxx;

  data : data_rec;
  data_alias : byte_array( 0 .. data_rec'size / 8 - 1 );
  for data_alias'address use data'address;
begin
  data.field_1 := 1;
  Ada.Text_Io.Put_Line( "field_1 before: " & Integer'IMAGE(
data.field_1 ) );
  Xxx( data_alias );
  Ada.Text_Io.Put_Line( "field_1 after: " & Integer'IMAGE( data.field_1 ) );
end testconv;

This makes the code look more like the original source, but requires an
additional declaration for each parameter passed to Xxx and still requires
the calls to be modified.

Sorry I don't have a better answer,

SteveD
>
> Thanks.
> --
> To reply by e-mail, please remove the extra dot
> in the given address:  m.collado -> mcollado





  parent reply	other threads:[~2002-10-19 13:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-18  8:24 Porting from Modula-2 to Ada Manuel Collado
2002-10-18  9:45 ` Bernd Specht
2002-10-18 10:33   ` Lutz Donnerhacke
2002-10-18 10:55     ` Jeffrey Creem
2002-10-18 11:21       ` Lutz Donnerhacke
2002-10-18 22:01         ` Jeffrey Creem
2002-10-18 21:29     ` Jeffrey Carter
2002-10-18 21:39       ` Jeffrey Carter
2002-10-18 11:20 ` Nicolas Cailín Paul Gloster
2002-10-18 15:14   ` Pat Rogers
2002-10-24 14:51     ` Colin Paul Gloster
2002-10-25  3:43       ` Dennis Lee Bieber
2003-02-04 14:12       ` Colin Paul Gloster
2003-02-09  6:07         ` Robert I. Eachus
2002-10-19 13:30 ` SteveD [this message]
2002-10-22  7:48   ` Manuel Collado
2002-10-22  7:55 ` Manuel Collado
2002-10-22 18:56   ` Jeffrey Carter
2002-10-23  9:08     ` Manuel Collado
replies disabled

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