Debian Codegraph @

gcc/testsuite/ada/acats/tests/cd/cd300050.am

raw
1 -- CD30005.A
2 --
3 -- Grant of Unlimited Rights
4 --
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
14 -- to do so.
15 --
16 -- DISCLAIMER
17 --
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
24 --*
25 --
26 -- OBJECTIVE:
27 -- Check that Address clauses are supported for imported subprograms.
28 --
29 -- TEST DESCRIPTION:
30 -- This test imports a simple C function and specifies it's location.
31 --
32 -- The implementation may choose to implement
33 -- Impdef.CD30005_1_Foreign_Address so as to dynamically call a C
34 -- function that returns the appropriate address for the external
35 -- function identified by Impdef.CD30005_1_External_Name.
36 --
37 -- TEST FILES:
38 -- CD300050.AM
39 -- CD300051.C -- the C function: (included below for reference)
40 --
41 -- SPECIAL REQUIREMENTS:
42 -- The file CD300051.C must be compiled with a C compiler.
43 -- Implementation dialects of C may require alteration of the C program
44 -- syntax. The program is included here for reference:
45 --
46 -- int _cd30005_1( Value )
47 -- {
48 -- /* int Value */
49 --
50 -- return Value + 1;
51 -- }
52 --
53 -- Implementations may require special linkage commands to include the
54 -- C code.
55 --
56 -- APPLICABILITY CRITERIA:
57 -- This test is not applicable to implementations not providing an interface
58 -- to C language units. OTHERWISE:
59 --
60 -- All implementations must attempt to compile this test.
61 --
62 -- For implementations validating against Systems Programming Annex (C):
63 -- this test must execute and report PASSED.
64 --
65 -- For implementations not validating against Annex C:
66 -- this test may report compile time errors at one or more points
67 -- indicated by "-- ANX-C RQMT", in which case it may be graded as inapplicable.
68 -- Otherwise, the test must execute and report PASSED.
69 --
70 --
71 -- CHANGE HISTORY:
72 -- 22 JUL 95 SAIC Initial version
73 -- 30 APR 96 SAIC Added commentary for 2.1
74 -- 09 MAY 96 SAIC Changed reporting for 2.1
75 -- 04 NOV 96 SAIC Added use type System.Address
76 -- 16 FEB 98 EDS Modified documentation.
77 -- 29 JUN 98 EDS Modified main program name.
78 --!
79
80 ----------------------------------------------------------------- CD30005_0
81
82 with Impdef;
83 package CD30005_0 is
84
85 -- Check that Address clauses are supported for imported subprograms.
86
87 type External_Func_Ref is access function(N:Integer) return Integer;
88 pragma Convention( C, External_Func_Ref );
89
90
91 function CD30005_1( I: Integer ) return Integer;
92
93 pragma Import( C, CD30005_1,
94 Impdef.CD30005_1_External_Name ); -- N/A => ERROR.
95
96 for CD30005_1'Address use
97 Impdef.CD30005_1_Foreign_Address; -- ANX-C RQMT.
98
99 procedure TC_Check_Imports;
100
101 end CD30005_0;
102
103 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
104
105 with Report;
106 with System.Storage_Elements;
107 with System.Address_To_Access_Conversions;
108 package body CD30005_0 is
109
110 use type System.Address;
111
112 procedure TC_Check_Imports is
113 S : External_Func_Ref := CD30005_1'Access;
114 I,K : Integer := 99;
115 begin
116
117 K := S.all(I);
118 if K /= 100 then
119 Report.Failed("C program returned" & Integer'Image(K));
120 end if;
121
122 I := CD30005_1( I );
123 if I /= 100 then
124 Report.Failed("C program returned" & Integer'Image(I));
125 end if;
126
127 if CD30005_1'Address /= Impdef.CD30005_1_Foreign_Address then
128 Report.Failed("Address not that specified");
129 end if;
130
131 end TC_Check_Imports;
132
133 end CD30005_0;
134
135 ------------------------------------------------------------------- CD300050
136
137 with Report;
138 with CD30005_0;
139
140 procedure CD300050 is
141
142 begin -- Main test procedure.
143
144 Report.Test ("CD30005",
145 "Check that Address clauses are supported for imported " &
146 "subprograms" );
147
148 -- Check that Address clauses are supported for imported subprograms.
149
150 CD30005_0.TC_Check_Imports;
151
152 Report.Result;
153
154 end CD300050;