ctypes.h

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 736 行 · 第 1/2 页

H
736
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  Internal CFE types.
*
****************************************************************************/


#define ENUM_HANDLE     ENUMPTR

typedef char    *SYM_NAMEPTR;

#include "cg.h"
#include "cgaux.h"

/* only for long_double */
#include "xfloat.h"

typedef back_handle     BACK_HANDLE;
typedef label_handle    LABEL_HANDLE;
typedef char            *NAME_HANDLE;
typedef cg_sym_handle   CGSYM_HANDLE;
typedef dbg_type        dbug_type;
typedef signed_64       int64;
typedef unsigned_64     uint64;

typedef void            *SYM_HANDLE;
typedef SYM_HANDLE      sym_handle;

#define L       I64LO32
#define H       I64HI32

/* CONST, VOLATILE can appear in typ->u.p.decl_flags and leaf->leaf_flags.
*  NEAR, FAR, HUGE can appear in typ->u.p.decl_flags, leaf->leaf_flags,
*                               and sym->attrib.
*  CDECL,PASCAL,FORTRAN,SYSCALL,STDCALL,OPTLINK,FASTCALL,WATCOM
*                       can appear in typ->u.p.decl_flags and sym->attrib.
*
* freed by CFOLD
*/
typedef enum    type_modifiers {    /* type   leaf   sym   */
    FLAG_NONE       = 0x0000,
    FLAG_CONST      = 0x0001,       /* Y0001  Y0001        */
    FLAG_VOLATILE   = 0x0002,       /* Y0002  Y0002        */
    FLAG_RESTRICT   = 0x0004,       /* see how this flies  */

    FLAG_NEAR       = 0x0008,       /* Y0008  Y0008  Y0008 */
    FLAG_FAR        = 0x0010,       /* Y0010  Y0010  Y0010 */
    FLAG_HUGE       = 0x0020,       /* Y0020  Y0020  Y0020 */
    FLAG_MEM_MODEL  = FLAG_NEAR | FLAG_FAR| FLAG_HUGE,


    LANG_CDECL      = 0x0040,       /* Y0040         Y0040 */
    LANG_PASCAL     = 0x0080,       /* Y0080         Y0080 */
    LANG_FORTRAN    = 0x00C0,       /* Y00C0         Y00C0 */
    LANG_SYSCALL    = 0x0100,       /* Y0100         Y0100 */     /* 04-jul-91 */
    LANG_STDCALL    = 0x0140,       /* Y0140         Y0140 */     /* 08-jan-92 */
    LANG_OPTLINK    = 0x0180,       /* Y0180         Y0180 */
    LANG_FASTCALL   = 0x01C0,       /* Y01C0         Y01C0 */
    LANG_WATCALL    = 0x0200,       /* Y0200         Y0200 */
    FLAG_LANGUAGES  = (LANG_CDECL  |
                       LANG_PASCAL |
                       LANG_FORTRAN|
                       LANG_SYSCALL|
                       LANG_STDCALL|
                       LANG_OPTLINK|
                       LANG_FASTCALL|
                       LANG_WATCALL ),
    FLAG_INTERRUPT  = (FLAG_NEAR+FLAG_FAR), /* interrupt function */
    /* FLAG_NEAR + FLAG_FAR both on ==> interrupt far */
    FLAG_SAVEREGS   = 0x0400,       /* Y0400         Y0400 */
    FLAG_LOADDS     = 0x0800,       /* Y0800         Y0800 */
    FLAG_EXPORT     = 0x1000,       /* Y1000         Y1000 */
    FLAG_BASED      = 0x2000,       /* Y2000         Y2000 _based ptr or var */
    FLAG_SEGMENT    = 0x4000,       /* Y4000         Y4000 __segment type */
    FLAG_FAR16      = 0x8000,       /* Y8000         Y8000 __far16 modifier */
    FLAG_UNALIGNED  =0x10000,       /*                     _Packed structures */
    FLAG_INLINE     =0x20000,       /* Y20000              _inline keyword */
    FLAG_WAS_ARRAY  =0x20000,       /* Y20000              for "char *argv[]" */
} type_modifiers;

typedef enum sym_flags {
    SYM_FUNCTION            = 0x01,     /* ON => function, OFF => variable */
    SYM_REFERENCED          = 0x02,     /* symbol was referenced in program */
    SYM_TYPE_GIVEN          = 0x04,     /* a ret type was specified for this func */
    SYM_EMITTED             = 0x04,     /* symbol has been emitted to cgen */
    SYM_DEFINED             = 0x08,     /* symbol has been defined */
    SYM_INITIALIZED         = 0x10,     /* variable has been initialized */
    SYM_OLD_STYLE_FUNC      = 0x10,     /* function defined with old-style defn */
    SYM_TEMP                = 0x20,     /* this is a temp created by MakeNewSym */
    SYM_CHECK_STACK         = 0x40,     /* function requires stack checking code */
    SYM_ASSIGNED            = 0x40,     /* variable has been assigned to */
    SYM_ADDR_TAKEN          = 0x80,     /* variable/func has had its address taken */
    SYM_IGNORE_UNREFERENCE  = 0x0100,   /* don't print msg if unreferenced */
    SYM_OK_TO_RECURSE       = 0x0200,   /* OK to do tail recursion */
    SYM_FUNC_RETURN_VAR     = 0x0400,   /* this is function return variable */
    SYM_FUNC_NEEDS_THUNK    = 0x0800,   /* need a thunk prolog? */
    SYM_BASED_STACK_VARS    = 0x1000,   /* _based(_segname("_STACK")) vars */
    SYM_USED_IN_PRAGMA      = 0x2000,   /* symbol referenced in a pragma */
    SYM_INTRINSIC           = 0x4000,   /* #pragma intrinsic(name) */
    SYM_TRY_VOLATILE        = 0x8000,   /* volatile because try is used */
} sym_flags;

typedef enum stg_classes {  // used in sym.stg_class
    SC_NULL         = 0,    // storage class not specified
    SC_FORWARD,             // forward declaration
    SC_EXTERN,              // extern
    SC_STATIC,              // static
    SC_TYPEDEF,             // typedef
    SC_AUTO,                // auto
    SC_REGISTER             // register
} stg_classes;

typedef enum declspec_class {      //note declspec field 2-bits in SYM_ENTRY
    DECLSPEC_NONE       =    0,
    DECLSPEC_DLLIMPORT,
    DECLSPEC_DLLEXPORT,
    DECLSPEC_THREAD,
} declspec_class;

typedef enum string_flags {     // string literal flags
    STRLIT_WIDE         = 0x80, // must not conflict with FLAG_MEM_MODEL
} string_flags;

typedef struct string_literal *STR_HANDLE;

#define SYM_INVALID     ((SYM_HANDLE)~0)    // invalid symbol; never a real sym

struct parm_list {
    struct  parm_list       *next_parm;
    struct  type_definition *parm_type;
};

struct array_info {
    unsigned long   dimension;
    int             refno;
    bool            unspecified_dim;    // or flexible array member?
};

typedef enum BASED_KIND {
    BASED_NONE,
    BASED_VOID,          //__based( void )       segment:>offset base op
    BASED_SELFSEG,       //__based( (__segment) __self ) use seg of self
    BASED_VAR,           //__based( <var> )             add to var pointer
    BASED_SEGVAR,        //__based( <var> )             add to var seg
    BASED_VARSEG,        //__based( (__segment) <var> ) ) use seg of var
    BASED_SEGNAME,       //__based( __segname( "name" )   use seg of segname
} BASED_KIND;

/* matches CompTable[] in ccheck.c */
/* matches CTypenames[] table in cdump.c */
/* matches CGDataType[] table in cgen.c */
/* matches AddResult[],SubResult[],IntResult[],ShiftResult[],BinResult[],
           CnvTable[] tables in cmath.c */
/* matches AsmDataType[] table in cpragx86.c */
/* matches CTypeSizes[] table in ctype.c */
typedef enum DATA_TYPE {
    TYPE_UNDEFINED = -1,
    TYPE_CHAR  =    0,      /* signed char */
    TYPE_UCHAR,
    TYPE_SHORT,
    TYPE_USHORT,
    TYPE_INT,
    TYPE_UINT,
    TYPE_LONG,
    TYPE_ULONG,
    TYPE_LONG64,
    TYPE_ULONG64,
    TYPE_FLOAT,
    TYPE_DOUBLE,
    TYPE_LONG_DOUBLE,
    TYPE_FIMAGINARY,
    TYPE_DIMAGINARY,
    TYPE_LDIMAGINARY,
    TYPE_BOOL,
    TYPE_POINTER,           /* types up to here are scalars */
    TYPE_ARRAY,
    TYPE_STRUCT,
    TYPE_UNION,
    TYPE_FUNCTION,
    TYPE_FIELD,             /* signed bit field */
    TYPE_VOID,
    TYPE_ENUM,
    TYPE_TYPEDEF,
    TYPE_UFIELD,            /* unsigned bit field */
    TYPE_DOT_DOT_DOT,       /* for the ... in prototypes */
    TYPE_PLAIN_CHAR,        /* char */
    TYPE_WCHAR,             /* L'c' - a wide character constant */
    TYPE_FCOMPLEX,
    TYPE_DCOMPLEX,
    TYPE_LDCOMPLEX,

    TYPE_LAST_ENTRY,        /* make sure this is always last */
} DATA_TYPE;

// values for type->type_flags
enum type_state {
    TF2_DWARF_DEF =  0x01,            // dwarf type has been defined
    TF2_DWARF_FWD =  0x02,            // dwarf forward reference
    TF2_DWARF     =  (TF2_DWARF_DEF|TF2_DWARF_FWD),  // dwarf is active
//  If the following flag is on, then it indicates a dummy typedef
//  It is used to record modifiers such as const, volatile
//  e.g.
//          struct foo { int a,b };
//          const struct foo *p;
//          type of p will be:
//          TYPE_POINTER -> dummy TYPE_TYPEDEF const -> TYPE_STRUCT
//
    TF2_DUMMY_TYPEDEF     = 0x04,   // gone now dummy typedef to record modifiers
    TF2_TYPE_PLAIN_CHAR   = 0x10,   // indicates plain char
    TF2_TYPE_SEGMENT      = 0x20,   // indicates __segment type
};

typedef struct type_definition {
    DATA_TYPE       decl_type;
    enum type_state type_flags;
    union {
        struct type_definition * object;
        int         object_index;       /* for pre-compiled headers */
    };
    struct  type_definition *next_type;
    union {
        dw_handle           dwarf_type; /* used for browsing info */
        dbug_type           debug_type; /* pass 2: debug type */
        int                 type_index; /* for pre-compiled hdrs */
    };
    union {
        struct {
            short int       segment;    /* TYPE_POINTER */
            SYM_HANDLE      based_sym;  /* var with seg of based ptr*/
            BASED_KIND      based_kind; /* kind of base variable    */
            type_modifiers  decl_flags; /* only symbols, fn and ptr have attribs */
        } p;
        union {
            struct tag_entry *tag;      /* STRUCT, UNION, ENUM */
            int             tag_index;  /* for pre-compiled header */
        };
        SYM_HANDLE          typedefn;   /* TYPE_TYPEDEF */
        struct {
            union {
                struct type_definition **parms;/* TYPE_FUNCTION */
                int         parm_index; /* for pre-compiled header */
            };
            type_modifiers  decl_flags; /* only symbols, fn and ptr have attribs */
        } fn;
        struct {                        /* TYPE_FIELD or TYPE_UFIELD */
            unsigned char field_width;  /* # of bits */
            unsigned char field_start;  /* # of bits to << by */
            unsigned char field_type;   /* TYPE_xxxx of field */
        } f;
        union {
            struct array_info *array;   /* TYPE_ARRAY */
            unsigned long array_dimension; /* for pre-compiled header */
        };
    } u;
} TYPEDEFN, *TYPEPTR;

extern  void WalkTypeList( void (*func)(TYPEPTR) );
extern  void WalkFuncTypeList( void (*func)(TYPEPTR,int) );

struct textsegment {    /* used for #pragma alloc_text(seg,func1,func2,...) */
    union {
        struct textsegment *next;
        int textsegment_len;        /* for pre-compiled header */
    };
    int     segment_number;
    int     index;
    char    segname[1];
};

typedef struct fname_list {
    union {
        struct fname_list *next;
        int    fname_len;           /* for pre-compiled header */
    };
    time_t   mtime;                 /* from stat.st_mtime */
    unsigned index;
    unsigned index_db;
    bool     rwflag;
    bool     once;
    char    *fullpath;
    char     name[1];
} *FNAMEPTR;

typedef struct rdir_list {
    union {
        struct rdir_list *next;
        int    name_len;           /* for pre-compiled header */
    };
    char     name[1];
} *RDIRPTR;

typedef struct incfile {
    struct incfile  *nextfile;
    int             len;
    char            filename[1];
} INCFILE;

typedef struct xref_entry {
    struct xref_entry       *next_xref;
    unsigned                linenum;
    unsigned                filenum;
} XREF_ENTRY, *XREFPTR;

extern  XREFPTR NewXref( XREFPTR );

struct sym_hash_entry {   /* SYMBOL TABLE structure */
    union {
        struct sym_hash_entry   *next_sym;
        int     hash_index;         /* for pre-compiled header */
    };
    union {
        TYPEPTR     sym_type;
        int         sym_type_index; /* for pre-compiled header */
    };
    SYM_HANDLE      handle;
#if defined(  __386__ )
    char            level;
#else
    unsigned        level;
#endif
    char            name[1];
};

typedef struct sym_hash_entry   *SYM_HASHPTR;
typedef struct expr_node        *TREEPTR;

typedef struct symtab_entry {           /* SYMBOL TABLE structure */
    char                *name;
    union {
        TYPEPTR         sym_type;
        int             sym_type_index;     /* for pre-compiled header */
    };
    SYM_HANDLE          handle;
    unsigned short      defn_file_index;    /* file this symbol is defined in */
    union {
        int             defn_line;          /* line number sym is defined on */
        int             index;              /* symbol index in object file */
    } d;
    union {
        BACK_HANDLE     backinfo;
        int             hash_value;
        temp_handle     return_var;         /* for the .R symbol */
    } info;
    union {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?