home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / testexten.adb < prev    next >
Encoding:
Text File  |  1995-12-07  |  3.8 KB  |  118 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/testexten.adb,v $ 
  2. -- $Revision: 1.2 $ $Date: 95/02/02 15:52:37 $ $Author: mg $ 
  3. -------------------------------------------------------------------------------
  4. --
  5. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS FURNISHED "AS IS" WITHOUT 
  6. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
  7. -- TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR 
  8. -- PURPOSE.  The user assumes the entire risk as to the accuracy and the 
  9. -- use of this file.
  10. --
  11. -- Copyright (c) Intermetrics, Inc. 1995
  12. -- Royalty-free, unlimited, worldwide, non-exclusive use, modification, 
  13. -- reproduction and further distribution of this file is permitted.
  14. --
  15. -------------------------------------------------------------------------------
  16.  
  17.  
  18. with Ada.Unchecked_Conversion;
  19. with Extensible;
  20. with Interfaces.C;
  21. with System.Storage_Elements;
  22. with Text_IO;
  23.  
  24. procedure TestExten is
  25.     use Interfaces.C;
  26.  
  27.     type Char_Array is array(0..0) of Char;
  28.  
  29.     type Rec1 is record
  30.         I     : Int;
  31.         Chars : Char_Array;
  32.     end record;
  33.  
  34.     R1: Rec1;
  35.  
  36.     package E1 is new Extensible(Rec1, Char, R1.Chars'Position);
  37.  
  38.  
  39.     type Int_Array is array(0..0) of Int;
  40.  
  41.     type Rec2 is record
  42.         C1   : Char;
  43.         Ints : Int_Array;
  44.     end record;
  45.  
  46.     R2: Rec2;
  47.     
  48.     package E2 is new Extensible(Rec2, Int, R2.Ints'Position);
  49.  
  50.     procedure Print_Offset (Rec      : String;
  51.                             F        : String; 
  52.                             Expected : Integer;
  53.                             Base     : System.Address;
  54.                             Field    : System.Address) is
  55.         use System.Storage_Elements;
  56.         use Text_IO;
  57.     begin
  58.         Put(Rec);
  59.         Put(".");
  60.         Put(F);
  61.         Put(" expected");
  62.         Put(Integer'Image(Expected));
  63.         Put(", got");
  64.         Put(Storage_Offset'Image(Field - Base));
  65.         if Expected /= Integer(Field - Base) then
  66.             Put(" *** error ***");
  67.         end if;
  68.         New_Line;
  69.     end Print_Offset;
  70.  
  71.     P1  : E1.Extended_Ptr;
  72.     AP1 : E1.Big_Array_Ptr;
  73.     P2  : E2.Extended_Ptr;
  74.     AP2 : E2.Big_Array_Ptr;
  75.  
  76.     function To_Addr is new Ada.Unchecked_Conversion (
  77.         E1.Extended_Ptr, System.Address);
  78.     function To_Addr is new Ada.Unchecked_Conversion (
  79.         E2.Extended_Ptr, System.Address);
  80.  
  81. begin
  82.     P1 := E1.Allocate(100);
  83.     Print_Offset("R1", "I", 0, R1'Address, R1.I'Address);
  84.     Print_Offset("R1", "chars(0)", 4, R1'Address, R1.Chars'Address);
  85.  
  86.     Print_Offset("P1", "I", 0, To_Addr(P1), E1.Fixed_Part(P1).I'Address);
  87.     Print_Offset("P1", "Chars", 4, To_Addr(P1), 
  88.     E1.Fixed_Part(P1).Chars'Address);
  89.     AP1 := E1.Array_Part(P1);
  90.     Print_Offset("AP1", "elem(0)", 4, To_Addr(P1), 
  91.     AP1.all'Address);
  92.     Print_Offset("AP1", "elem(0)", 4, To_Addr(P1), 
  93.     AP1.all(0)'Address);
  94.     Print_Offset("AP1", "elem(5)", 4+(5*Char'Size/8), To_Addr(P1), 
  95.     AP1.all(5)'Address);
  96.     Print_Offset("AP1", "elem(100)", 4+(100*Char'Size/8), To_Addr(P1), 
  97.     AP1.all(100)'Address);
  98.  
  99.     Text_IO.New_Line;
  100.     P2 := E2.Allocate(100);
  101.     Print_Offset("R2", "C1", 0, R2'Address, R2.C1'Address);
  102.     Print_Offset("R2", "Ints(0)", 4, R2'Address, R2.Ints'Address);
  103.     Print_Offset("P2", "C1", 0, To_Addr(P2), E2.Fixed_Part(P2).C1'Address);
  104.     Print_Offset("P2", "Ints", 4, To_Addr(P2), 
  105.     E2.Fixed_Part(P2).Ints'Address);
  106.     AP2 := E2.Array_Part(P2);
  107.     Print_Offset("AP2", "elem(0)", 4, To_Addr(P2), 
  108.     AP2.all'Address);
  109.     Print_Offset("AP2", "elem(0)", 4, To_Addr(P2), 
  110.     AP2.all(0)'Address);
  111.     Print_Offset("AP2", "elem(5)", 4+(5*Int'Size/8), To_Addr(P2), 
  112.     AP2.all(5)'Address);
  113.     Print_Offset("AP2", "elem(100)", 4+(100*Int'Size/8), To_Addr(P2), 
  114.     AP2.all(100)'Address);
  115.     Print_Offset("AP2", "elem(100)", 4+(100*Int'Size/8), To_Addr(P2), 
  116.     E2.Array_Part(P2)(100)'Address);
  117. end TestExten;
  118.