cgfront.h

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

H
1,480
字号
/****************************************************************************
*
*                            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:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#ifndef __CGRONT__H__
#define __CGRONT__H__

// CGFRONT.H -- interface with code-generation for front-end

#include "cgdata.h"
#include "cgiobuff.h"
#include "cgio.h"
#include "icodes.h"
#include "segment.h"
#include "ptree.h"
#include "module.h"
#include "intsupp.h"
#include "pragdefn.h"

#define BIT_VECT( b1, b2, b3, b4, b5, b6, b7, b8 ) \
    b8 + b7*2 + b6*4 + b5*8 + b4*16 + b3*32 + b2*64 +b1*128

typedef enum                    // DTOR_KIND -- kind of DTORing to be applied
{   DTORING_NONE                // - none
,   DTORING_SCOPE               // - auto variable or component in DTOR
,   DTORING_TEMP                // - temporary variable
,   DTORING_COMPONENT           // - component
} DTOR_KIND;

enum                            // DEFINE TYPE OF POINTER CONVERSION
{   CNVPTR_DERIVED_ONLY    = 0  // - can only convert derived
,   CNVPTR_VIRT_TO_DERIVED = 1  // - can convert virtual to derived
,   CNVPTR_CAST            = 2  // - a cast conversion (from the C++ source)
,   CNVPTR_CONST_VOLATILE  = 4  // - const/volatile checks may be needed later
,   CNVPTR_NO_TRUNC        = 8  // - don't do truncation check
};

typedef enum                    // DEFINE RESULTS OF CONVERSION
{   CNV_OK                      // - conversion successful or not required
,   CNV_OK_TRUNC                // - as above, but truncation occurred
,   CNV_OK_CV                   // - ok, but need to check const/volatile
,   CNV_OK_TRUNC_CV             // - truncated, need to check const/vol.
,   CNV_OK_TRUNC_CAST_CV        // - cast truncated, need to check const/vol.
,   CNV_OK_TRUNC_CAST           // - ptr truncation on cast occurred
,   CNV_WORKED = CNV_OK_TRUNC_CAST // ********* above ==> worked
,   CNV_TRUNC_THIS              // - truncating "this" pointer
,   CNV_ERR                     // - conversion attempted, error occurred
,   CNV_VIRT_DER                // - attempt to convert virt. base to derived
,   CNV_IMPOSSIBLE              // - conversion impossible
,   CNV_AMBIGUOUS               // - conversion ambiguous
,   CNV_PRIVATE                 // - conversion through a private base
,   CNV_PROTECTED               // - conversion through a protected base
} CNV_RETN;

typedef enum                    // DEFINE TYPE OF SIZE CONVERSION NEEDED
{   CNV_PTR_SAME                // - no conversion required
,   CNV_PTR_EXPAND              // - pointer must be enlarged
,   CNV_PTR_TRUNCATE            // - pointer must be truncated
} CNV_PTR_RESULT;

typedef enum                    // DEFINE TYPES OF CONVERSIONS
{   CNV_INIT        = 0x0001    // - initialization (direct)
,   CNV_INIT_COPY   = 0x8001    // - initialization (copy)
,   CNV_FUNC_ARG    = 0x0002    // - function argument
,   CNV_FUNC_THIS   = 0x0042    // - 'this' ptr for function
,  CNV_FUNC_CD_THIS = 0x0082   // - 'this' ptr for CTOR, DTOR
,   CNV_FUNC_RET    = 0x0004    // - function return
,   CNV_FUNC_DARG   = 0x0044    // - function return (of default argument)
,   CNV_CAST        = 0x0008    // - explicit cast
,   CNV_EXPR        = 0x0010    // - expression
,   CNV_ASSIGN      = 0x0020    // - assignment

                                // DERIVED TYPES OF CONVERSIONS

,   CNV_TYPE = ( CNV_INIT | CNV_FUNC_ARG | CNV_FUNC_RET | CNV_EXPR
               | CNV_CAST | CNV_ASSIGN )                        // 0x003F
} CNV_REQD;

#define _CNV_TYPE( val ) ((val) & CNV_TYPE )

typedef enum                    // CODES FOR PC POINTER REPRESENTATIONS
{   PC_PTR_REGULAR              // - regular pointer
,   PC_PTR_BASED_STRING         // - based( __segment(name) )
        = TF1_BASED_STRING >> 8
,   PC_PTR_BASED_SELF           // - based( __self )
        = TF1_BASED_SELF >> 8
,   PC_PTR_BASED_VOID           // - based( void )
        = TF1_BASED_VOID >> 8
,   PC_PTR_BASED_FETCH          // - based( ptr )
        = TF1_BASED_FETCH >> 8
,   PC_PTR_BASED_ADD            // - based( segment # )
        = TF1_BASED_ADD >> 8
,   PC_PTR_FAR16                // - far16
,   PC_PTR_NOT                  // - not a pointer
} PC_PTR;

enum                            // CODES FOR ADDR(FUNCTION)
{   ADDR_FN_NONE                // - not addr of function
,   ADDR_FN_ONE                 // - addr of function (not overloaded)
,   ADDR_FN_MANY                // - addr of function (overloaded)
,   ADDR_FN_ONE_USED            // - use of function (not overloaded)
,   ADDR_FN_MANY_USED           // - use of function (overloaded)
};

enum                            // control bits for EffectCtor
{   EFFECT_EXACT        = 0x01  // - exact version of class
,   EFFECT_VALUE_THIS   = 0x02  // - force value of EffectCtor expr to be 'this'
,   EFFECT_DECOR_COMP   = 0x10  // - add component decoration
,   EFFECT_DECOR_SCOPE  = 0x20  // - add scope decoration
,   EFFECT_DECOR_TEMP   = 0x40  // - add temporary decoration
,   EFFECT_VIRTUAL      = 0x80  // - is a virtual base
,   EFFECT_NULL         = 0x00

,   EFFECT_CTOR_DECOR   =       // - add decoration
        EFFECT_DECOR_COMP  |
        EFFECT_DECOR_SCOPE |
        EFFECT_DECOR_TEMP
};

typedef enum                    // TEMP_TYPE:
{   TEMP_TYPE_NONE              // - not defined
,   TEMP_TYPE_EXPR              // - auto, expression duration
,   TEMP_TYPE_BLOCK             // - auto, block duration
,   TEMP_TYPE_STATIC            // - static
} TEMP_TYPE;

typedef struct                  // USED FOR DIAGNOSIS OF CONVERSIONS
{   int msg_impossible;         // - error message for CNV_IMPOSSIBLE
    int msg_ambiguous;          // - error message for CNV_AMBIGUOUS
    int msg_virt_der;           // - error message for CNV_VIRT_DIR
    int msg_private;            // - error message for CNV_PRIVATE
    int msg_protected;          // - error message for CNV_PROTECTED
} CNV_DIAG;

typedef struct                  // USED FOR DIAGNOSIS OF CALL
{   int msg_ambiguous;          // - when ambiguous
    int msg_no_match_one;       // - no match, only one function declared
    int msg_no_match_many;      // - no match, several functions declared
} CALL_DIAG;

typedef struct                  // USED FOR DIAGNOSIS OF SYMBOL ACCESS
{   int msg_no_this;            // - "this" required, not supplied
    int msg_extra_this;         // - "this" supplied, may not be used
    int msg_enclosing;          // - "this" accesses item in enclosing class
} SYMBOL_DIAG;

typedef enum                    // CTD -- common-type derivations
{   CTD_NO                      // - neither derived from other
,   CTD_LEFT                    // - left derived, non-virtually
,   CTD_LEFT_VIRTUAL            // - left derived, virtually
,   CTD_LEFT_AMBIGUOUS          // - left derived, ambiguously
,   CTD_LEFT_PRIVATE            // - left derived, across private base
,   CTD_LEFT_PROTECTED          // - left derived, across protected base
,   CTD_RIGHT                   // - right derived, non-virtually
,   CTD_RIGHT_VIRTUAL           // - right derived, virtually
,   CTD_RIGHT_AMBIGUOUS         // - right derived, ambiguously
,   CTD_RIGHT_PRIVATE           // - right derived, across private base
,   CTD_RIGHT_PROTECTED         // - right derived, across protected base
} CTD;

typedef enum                    // CALL_OPT -- types of call optimizations
{   CALL_OPT_NONE               // - none detected
,   CALL_OPT_ERR                // - error (used for convenience)
,   CALL_OPT_CTOR               // - ctor to be optimized
,   CALL_OPT_FUN_CALL           // - function-call to be optimized
,   CALL_OPT_BIN_COPY           // - binary-copy optimization
} CALL_OPT;


// MACROS

#define ___NodeIsOp(node,op) ( (node)->cgop == (op) )
#define conversionWorked( val ) ( (val) <= CNV_WORKED )


// PROTOTYPES : exposed to C++ compiler

PTREE AddCastNode               // ADD A CAST NODE
    ( PTREE expr                // - expression
    , TYPE type )               // - type
;
TYPE AnalyseAssignment(         // ANALYSE assignment operation
    TYPE left,                  // - assignement type
    PTREE right )               // - right node
;
PTREE AnalyseBoolExpr(          // ANALYZE A BOOLEAN EXPRESSION
    PTREE expr )
;
PTREE AnalyseCall(              // ANALYSIS FOR CALL
    PTREE expr,                 // - call expression
    CALL_DIAG *diagostic )      // - diagnostics used for function problems
;
CALL_OPT AnalyseCallOpts(       // ANALYSE CALL OPTIMIZATIONS
    TYPE type,                  // - class type of target operand
    PTREE src,                  // - source operand
    PTREE* a_dtor,              // - addr[ CO_DTOR ]
    PTREE* a_right )            // - addr[ base source operand ]
;
PTREE AnalyseCtorExpr(          // ANALYSE CTOR EXPRESSION
    PTREE expr )                // - expression
;
PTREE AnalyseDelete(            // ANALYSE DELETE OPERATOR
    PTREE expr,                 // - delete expression
    boolean in_dtor )           // - TRUE ==> call from inside DTOR
;
PTREE AnalyseDtorCall(          // ANALYSIS FOR SPECIAL DTOR CALLS
    TYPE class_type,            // - class to be destructed
    PTREE this_node,            // - expression for address of class
    target_offset_t extra )     // - constant for extra second parm
;
PTREE AnalyseInitExpr(          // ANALYZE AN INITIALIZATION EXPRESSION
    PTREE expr,                 // - expresion
    boolean is_static )         // - is target a static
;
PTREE AnalyseIntegralExpr(      // ANALYZE AN EXPRESSION, MAKE IT AN INT. VALUE
    PTREE expr )
;
void AnalyseIntTrunc(           // ANALYSE INTEGRAL TRUNCATION
    PTREE expr,                 // - expression for error
    TYPE type )                 // - target type
;
boolean AnalyseLvalue(          // ANALYSE AN LVALUE
    PTREE *a_expr )             // - addr( expression to be analysed )
;
boolean AnalyseLvalueAddrOf(    // ANALYSE LVALUE FOR "&"
    PTREE *a_expr )             // - addr[ expression to be analysed ]
;
PTREE AnalyseLvArrow(           // ANALYSE LVALUE "->"
    PTREE expr )                // - addr[ expression to be analysed ]
;
PTREE AnalyseLvDot(             // ANALYSE LVALUE "."
    PTREE expr )                // - addr[ expression to be analysed ]
;
PTREE AnalyseNew(               // ANALYSE A "NEW" OPERATOR
    PTREE expr,                 // - "new" expression
    TYPE type )                 // - type of expression
;
PTREE AnalyseNode(              // ANALYSE PTREE NODE FOR SEMANTICS
    PTREE expr )                // - current node
;
PTREE AnalyseOffsetOf(          // ANALYSE OFFSETOF
    PTREE expr )                // - expression to be analysed
;
PTREE AnalyseOperator(          // ANALYSE AN OPERATOR
    PTREE expr )                // - expression
;
unsigned AnalysePtrCV(          // CHECK PTR CONVERSION FOR CONST/VOLATILE
    PTREE expr,                 // - expression for error
    TYPE proto,                 // - type of target
    TYPE argument,              // - type of source
    unsigned conversion )       // - type of conversion
;
PTREE AnalyseReturnClassVal     // RETURN CLASS VALUE
    ( PTREE retn_expr )         // - expression for return
;
PTREE AnalyseReturnExpr(        // ANALYSE A RETURN EXPRESSION
    SYMBOL func,                // - function to which the expression applies
    PTREE expr )                // - expression
;
PTREE AnalyseReturnSimpleVal    // RETURN A SIMPLE VALUE
    ( PTREE expr )              // - expression for return
;
PTREE AnalyseStmtExpr(          // ANALYZE A STATEMENT EXPRESSION
    PTREE expr )
;
PTREE AnalyseRawExpr(           // ANALYZE A SUB-TREE WITH NO EXTRA SEMANTICS
    PTREE expr )
;

⌨️ 快捷键说明

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