1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
.. _Intrinsic_Subprograms:
*********************
Intrinsic Subprograms
*********************
.. index:: Intrinsic Subprograms
GNAT allows a user application program to write the declaration:
.. code-block:: ada
pragma Import (Intrinsic, name);
providing that the name corresponds to one of the implemented intrinsic
subprograms in GNAT, and that the parameter profile of the referenced
subprogram meets the requirements. This chapter describes the set of
implemented intrinsic subprograms, and the requirements on parameter profiles.
Note that no body is supplied; as with other uses of pragma Import, the
body is supplied elsewhere (in this case by the compiler itself). Note
that any use of this feature is potentially non-portable, since the
Ada standard does not require Ada compilers to implement this feature.
.. _Intrinsic_Operators:
Intrinsic Operators
===================
.. index:: Intrinsic operator
All the predefined numeric operators in package Standard
in ``pragma Import (Intrinsic,..)``
declarations. In the binary operator case, the operands must have the same
size. The operand or operands must also be appropriate for
the operator. For example, for addition, the operands must
both be floating-point or both be fixed-point, and the
right operand for ``"**"`` must have a root type of
``Standard.Integer'Base``.
You can use an intrinsic operator declaration as in the following example:
.. code-block:: ada
type Int1 is new Integer;
type Int2 is new Integer;
function "+" (X1 : Int1; X2 : Int2) return Int1;
function "+" (X1 : Int1; X2 : Int2) return Int2;
pragma Import (Intrinsic, "+");
This declaration would permit 'mixed mode' arithmetic on items
of the differing types ``Int1`` and ``Int2``.
It is also possible to specify such operators for private types, if the
full views are appropriate arithmetic types.
.. _Compilation_ISO_Date:
Compilation_ISO_Date
====================
.. index:: Compilation_ISO_Date
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Source_Info``. The only useful use of the
intrinsic import in this case is the one in this unit, so an
application program should simply call the function
``GNAT.Source_Info.Compilation_ISO_Date`` to obtain the date of
the current compilation (in local time format YYYY-MM-DD).
.. _Compilation_Date:
Compilation_Date
================
.. index:: Compilation_Date
Same as Compilation_ISO_Date, except the string is in the form
MMM DD YYYY.
.. _Compilation_Time:
Compilation_Time
================
.. index:: Compilation_Time
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Source_Info``. The only useful use of the
intrinsic import in this case is the one in this unit, so an
application program should simply call the function
``GNAT.Source_Info.Compilation_Time`` to obtain the time of
the current compilation (in local time format HH:MM:SS).
.. _Enclosing_Entity:
Enclosing_Entity
================
.. index:: Enclosing_Entity
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Source_Info``. The only useful use of the
intrinsic import in this case is the one in this unit, so an
application program should simply call the function
``GNAT.Source_Info.Enclosing_Entity`` to obtain the name of
the current subprogram, package, task, entry, or protected subprogram.
.. _Exception_Information:
Exception_Information
=====================
.. index:: Exception_Information'
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Current_Exception``. The only useful
use of the intrinsic import in this case is the one in this unit,
so an application program should simply call the function
``GNAT.Current_Exception.Exception_Information`` to obtain
the exception information associated with the current exception.
.. _Exception_Message:
Exception_Message
=================
.. index:: Exception_Message
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Current_Exception``. The only useful
use of the intrinsic import in this case is the one in this unit,
so an application program should simply call the function
``GNAT.Current_Exception.Exception_Message`` to obtain
the message associated with the current exception.
.. _Exception_Name:
Exception_Name
==============
.. index:: Exception_Name
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Current_Exception``. The only useful
use of the intrinsic import in this case is the one in this unit,
so an application program should simply call the function
``GNAT.Current_Exception.Exception_Name`` to obtain
the name of the current exception.
.. _File:
File
====
.. index:: File
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Source_Info``. The only useful use of the
intrinsic import in this case is the one in this unit, so an
application program should simply call the function
``GNAT.Source_Info.File`` to obtain the name of the current
file.
.. _Line:
Line
====
.. index:: Line
This intrinsic subprogram is used in the implementation of the
library package ``GNAT.Source_Info``. The only useful use of the
intrinsic import in this case is the one in this unit, so an
application program should simply call the function
``GNAT.Source_Info.Line`` to obtain the number of the current
source line.
.. _Shifts_and_Rotates:
Shifts and Rotates
==================
.. index:: Shift_Left
.. index:: Shift_Right
.. index:: Shift_Right_Arithmetic
.. index:: Rotate_Left
.. index:: Rotate_Right
In standard Ada, the shift and rotate functions are available only
for the predefined modular types in package ``Interfaces``. However, in
GNAT it is possible to define these functions for any integer
type (signed or modular), as in this example:
.. code-block:: ada
function Shift_Left
(Value : T;
Amount : Natural) return T
with Import, Convention => Intrinsic;
The function name must be one of
Shift_Left, Shift_Right, Shift_Right_Arithmetic, Rotate_Left, or
Rotate_Right. T must be an integer type. T'Size must be
8, 16, 32 or 64 bits; if T is modular, the modulus
must be 2**8, 2**16, 2**32 or 2**64.
The result type must be the same as the type of ``Value``.
The shift amount must be Natural.
The formal parameter names can be anything.
A more convenient way of providing these shift operators is to use the
Provide_Shift_Operators pragma, which provides the function declarations and
corresponding pragma Import's for all five shift functions. For signed types
the semantics of these operators is to interpret the bitwise result of the
corresponding operator for modular type. In particular, shifting a negative
number may change its sign bit to positive.
.. _Source_Location:
Source_Location
===============
.. index:: Source_Location
This intrinsic subprogram is used in the implementation of the
library routine ``GNAT.Source_Info``. The only useful use of the
intrinsic import in this case is the one in this unit, so an
application program should simply call the function
``GNAT.Source_Info.Source_Location`` to obtain the current
source file location.
|