跳至内容

Ada 编程/库/接口.COBOL

来自维基教科书,开放书籍,开放世界

Ada. Time-tested, safe and secure.
Ada. 经时间考验,安全可靠。

此语言特性从 Ada 95 开始可用。

接口.COBOL预定义语言环境 自 Ada 95 以来的一部分。

package Interfaces.COBOL is
 pragma Preelaborate(COBOL);

--  Types and operations for internal data representations

 type Floating      is digits implementation-defined;
 type Long_Floating is digits implementation-defined;

 type Binary      is range implementation-defined;
 type Long_Binary is range implementation-defined;

 Max_Digits_Binary      : constant := implementation-defined;
 Max_Digits_Long_Binary : constant := implementation-defined;

 type Decimal_Element  is mod implementation-defined;
 type Packed_Decimal is array (Positive range <>) of Decimal_Element
    with Pack;

 type COBOL_Character is implementation-defined character type;

 Ada_To_COBOL : array (Character) of COBOL_Character := implementation-defined;

 COBOL_To_Ada : array (COBOL_Character) of Character := implementation-defined;

 type Alphanumeric is array (Positive range <>) of COBOL_Character
    with Pack;

 function To_COBOL (Item : in String) return Alphanumeric;
 function To_Ada   (Item : in Alphanumeric) return String;

 procedure To_COBOL (Item       : in String;
                     Target     : out Alphanumeric;
                     Last       : out Natural);

 procedure To_Ada (Item     : in Alphanumeric;
                   Target   : out String;
                   Last     : out Natural);

 type Numeric is array (Positive range <>) of COBOL_Character
    with Pack;
    
 --  Formats for COBOL data representations

 type Display_Format is private;

 Unsigned             : constant Display_Format;
 Leading_Separate     : constant Display_Format;
 Trailing_Separate    : constant Display_Format;
 Leading_Nonseparate  : constant Display_Format;
 Trailing_Nonseparate : constant Display_Format;

 type Binary_Format is private;

 High_Order_First  : constant Binary_Format;
 Low_Order_First   : constant Binary_Format;
 Native_Binary     : constant Binary_Format;

 type Packed_Format is private;

 Packed_Unsigned   : constant Packed_Format;
 Packed_Signed     : constant Packed_Format;

 --  Types for external representation of COBOL binary data

 type Byte is mod 2**COBOL_Character'Size;
 type Byte_Array is array (Positive range <>) of Byte
    with Pack;

 Conversion_Error : exception;

 generic
    type Num is delta <> digits <>;
 package Decimal_Conversions is

    --  Display Formats: data values are represented as Numeric

    function Valid (Item   : in Numeric;
                    Format : in Display_Format) return Boolean;

    function Length (Format : in Display_Format) return Natural;

    function To_Decimal (Item   : in Numeric;
                         Format : in Display_Format) return Num;

    function To_Display (Item   : in Num;
                         Format : in Display_Format) return Numeric;

    --  Packed Formats: data values are represented as Packed_Decimal

    function Valid (Item   : in Packed_Decimal;
                    Format : in Packed_Format) return Boolean;

    function Length (Format : in Packed_Format) return Natural;

    function To_Decimal (Item   : in Packed_Decimal;
                         Format : in Packed_Format) return Num;

    function To_Packed (Item   : in Num;
                        Format : in Packed_Format) return Packed_Decimal;

    --  Binary Formats: external data values are represented as Byte_Array

    function Valid (Item   : in Byte_Array;
                    Format : in Binary_Format) return Boolean;

    function Length (Format : in Binary_Format) return Natural;
    function To_Decimal (Item   : in Byte_Array;
                         Format : in Binary_Format) return Num;

    function To_Binary (Item   : in Num;
                      Format : in Binary_Format) return Byte_Array;

    --  Internal Binary formats: data values are of type Binary or Long_Binary

    function To_Decimal (Item : in Binary)      return Num;
    function To_Decimal (Item : in Long_Binary) return Num;

    function To_Binary      (Item : in Num)  return Binary;
    function To_Long_Binary (Item : in Num)  return Long_Binary;

 end Decimal_Conversions;

private
   ... --  not specified by the language
end Interfaces.COBOL;

另请参阅

[编辑 | 编辑源代码]

维基教科书

[编辑 | 编辑源代码]

外部示例

[编辑源代码]

Ada 参考手册

[编辑 | 编辑源代码]

开源实现

[编辑 | 编辑源代码]

FSF GNAT

drake

华夏公益教科书