/*HEAD MACH_DATATYPES HHH SYSS */
/*CLASS MACH */
/*==============================================================================

              Copyright (c) 1998,1999 Unigraphics Solutions Inc.
                     Unpublished - All rights reserved

================================================================================
File description:                                                                                                              
    Data types used by MACH and om.h

================================================================================
   Date      Name                    Description of Change

30-Apr-1998  Jack Marr               Broken out from mach.h
18-May-1998  Mike Abbott             Add to Cambridge definitive copy
10-Dec-1998  Jack Marr               Add protos, fix K&R arglists, general QAZ
25-Jan-1999  Adrian Brown            CCR ip1 of v16.0
16-Jul-1999  Jack Marr               Add 64-bit and int-ptr data types
30-Sep-1999  Jack Marr               Revise qaz types to avoid SGI conflict
04-Oct-1999  Adrian Brown            CCR ip19 of v160
26-Oct-1999  Lavarini                Add MACH_type_information_t
29-Oct-1999  Gary Smethers           V16 phase 20 CCR
31-Oct-2000  Jack Marr               Formatting macros for int64 && intptr types
25-Jul-2001  Reger                   Remove OSF
27-Oct-2003  Jack Marr               HPI port - same as HPP
02-Nov-2004  Keith Jaskot             Ported to SUSE Linux
17-Nov-2004  Jack Marr               Remove __lint blocks & IBM format override
17-Mar-2005  Jack Marr               Need to define __STDC_FORMAT_MACROS w/g++
28-Mar-2005  Jack Marr               Correct default format strings
24-Oct-2006  Bernie Solomon          Add inttypes.h for Sun 32 bit
$HISTORY$
==============================================================================*/

#ifndef MACH_DATATYPES_H_INCLUDED
#define MACH_DATATYPES_H_INCLUDED

typedef struct MACH_type_information_s
  { int alignment;
    int size;
  } MACH_type_information_t, *MACH_type_information_p_t;

/*  <MRA> 20-Jan-92
    Existing values cannot be changed in this array, but new ones can be added
    on the end.  Two previous ones have been removed.  However, MACH_type_max
    is used in the bowels of the OM, and changing it would cause serious schema
    conversion problems. Now, boys and girls, aren't we lucky nice Uncle Michael
    removed two values, or we wouldn't have any leeway at all, would we?

    MACH_type_tag is no longer a "primary" machine value (the TAG module just
    uses (unsigned, long) ints), but it is retained because OM_type_tag (see
    om.inc) was defined in terms of it when it was, and has to keep the same
    value.

    <JLM> 30-Apr-98
    Break out these data types from mach.h since these are used by om.h
    and we thus get massive recompiles anytime anything in mach.h is tweaked.
*/
#define MACH_type_invalid   -1
#define MACH_type_logical    0
#define MACH_type_char       1
#define MACH_type_short      2
#define MACH_type_int        3 
#define MACH_type_pointer    4
#define MACH_type_float      5
#define MACH_type_double     6
#define MACH_type_byte       7
#define MACH_type_date       8
#define MACH_type_tag        9
#define MACH_type_max_used   9
#define MACH_type_max       11

/*
 * Define 64-bit int types and int-ptr compatibility types.
 *
 * <JLM> 16-Jul-99
 * Eventually this will be simplified by vendor adherence to the next 
 * revision of the ISO C standard (C9X).  The current draft, n869, specifies 
 * the use of types int64_t, uint64_t, and uintptr_t, and macros which could
 * be used to test for the existence of such types (e.g. INT64_MAX).  These 
 * types and macros are to be defined in <stdint.h>, which will be included
 * by <inttypes.h>.   The latter also provides printf/scanf field specifiers
 * via macros.  The following blurb was adapted from the HP-UX docs:
 *
 * The following macros can be used even when an implementation has not
 * extended the printf/scanf family of functions. 
 *
 * The form of the names of the macros is either "PRI" for printf specifiers
 * or "SCN" for scanf specifiers followed by the conversion specifier letter
 * followed by the datatype size. For example, PRId64 is the macro for
 * the printf d conversion specifier with the flags for 64 bit datatype.
 *
 * Separate printf versus scanf macros are given because typically different
 * size flags must prefix the conversion specifier letter.
 *
 ** An example using one of these macros:
 *
 *      MACH_uint64_t u;
 *      printf("u = %" PRIx64 "\n", u);
 *
 * The appropriate printf macros are:
 *
 *                      %d      %i      %u      %o      %x      %X      %p
 *     MACH_int64_t   PRId64  PRIi64
 *     MACH_uint64_t                  PRIu64  PRIo64  PRIx64  PRIX64
 *     MACH_uintptr_t                 PRIuPTR PRIoPTR PRIxPTR PRIXPTR   %p
 *
 * The appropriate scanf macros are:
 *
 *                       %d       %i       %u       %o       %x       %p
 *     MACH_int64_t    SCNd64   SCNi64
 *     MACH_uint64_t                     SCNu64   SCNo64   SCNx64
 *     MACH_uintptr_t                    SCNuPTR  SCNoPTR  SCNxPTR    %p
 */

#ifndef UNIDEFS_H_INCLUDED
#error unidefs.h must be included prior to mach_datatypes.h
#endif

#if defined(IBM_AIX)
#include <inttypes.h>

typedef int64_t             MACH_int64_t;
typedef uint64_t            MACH_uint64_t;
typedef uintptr_t           MACH_uintptr_t;

#elif defined(HPUX)
#include <inttypes.h>

/* The +e switch is required to access 64-bit types. */

typedef int64_t             MACH_int64_t;
typedef uint64_t            MACH_uint64_t;
typedef uintptr_t           MACH_uintptr_t;

#elif defined(SGI)
#include <inttypes.h>

typedef int64_t             MACH_int64_t;
typedef uint64_t            MACH_uint64_t;
typedef uintptr_t           MACH_uintptr_t;

#elif defined(SUN)

/* 
 * <JLM> 31-Oct-00
 * This really only works if we don't use the -Xc switch, in which case the 
 * first conditional block is used since __STDC__==0.  Otherwise we get a 
 * definition of longlong_t using a union instead of an arithmetic type.  
 * Eventually it might be the case that Sun defines int64_t in the -Xc 
 * (strict ANSI) mode since the ANSI C99 standard supports that.  But once 
 * we've dropped the -Xc switch we're probably not going to reinstate it.
 */

#if defined(_LP64) || (__STDC__ - 0 == 0 && !defined(_NO_LONGLONG))
#include <inttypes.h>
typedef int64_t             MACH_int64_t;
typedef uint64_t            MACH_uint64_t;
#else
#include <sys/types.h>
typedef longlong_t          MACH_int64_t;
typedef u_longlong_t        MACH_uint64_t;
#endif

typedef uintptr_t           MACH_uintptr_t;

#elif defined(WNT)
#include <inttypes.h>

typedef int64_t             MACH_int64_t;
typedef uint64_t            MACH_uint64_t;
typedef uintptr_t           MACH_uintptr_t;


#elif defined(LNX64)
#define __STDC_FORMAT_MACROS
#include <inttypes.h>

typedef int64_t            MACH_int64_t;
typedef uint64_t        MACH_uint64_t;
typedef uintptr_t        MACH_uintptr_t;

#else
#error Porting attention required
#endif

#endif /* MACH_DATATYPES_H_INCLUDED */
