Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
s_typ_init.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 
00037 static char USMID[] = "\n@(#)5.0_pl/sources/s_typ_init.c        5.3     06/16/99 10:02:23\n";
00038 
00039 # include "defines.h"           /* Machine dependent ifdefs */
00040 
00041 # include "host.m"              /* Host machine dependent macros.*/
00042 # include "host.h"              /* Host machine dependent header.*/
00043 # include "target.m"            /* Target machine dependent macros.*/
00044 # include "target.h"            /* Target machine dependent header.*/
00045 
00046 # include "globals.m"
00047 # include "tokens.m"
00048 # include "sytb.m"
00049 # include "s_globals.m"
00050 # include "debug.m"
00051 # include "s_asg_expr.m"
00052 
00053 # include "globals.h"
00054 # include "tokens.h"
00055 # include "sytb.h"
00056 # include "s_globals.h"
00057 
00058 
00059 /*****************************************************************\
00060 |* function prototypes of static functions declared in this file *|
00061 \*****************************************************************/
00062 
00063 static  boolean attr_init_semantics(opnd_type *, int, int, expr_arg_type *);
00064 static  boolean const_init_semantics(opnd_type *, int, int);
00065 static  void    process_all_initialized_cpnts(opnd_type *, int, operator_type);
00066 
00067 
00068 /******************************************************************************\
00069 |*                                                                            *|
00070 |* Description:                                                               *|
00071 |*      Do semantics for type declaration initializations.                    *|
00072 |*                                                                            *|
00073 |* Input parameters:                                                          *|
00074 |*      NONE                                                                  *|
00075 |*                                                                            *|
00076 |* Output parameters:                                                         *|
00077 |*      NONE                                                                  *|
00078 |*                                                                            *|
00079 |* Returns:                                                                   *|
00080 |*      NOTHING                                                               *|
00081 |*                                                                            *|
00082 \******************************************************************************/
00083 
00084 void type_init_semantics (void)
00085 
00086 {
00087    int                  attr_idx;
00088    int                  col;
00089    expr_arg_type        expr_desc;
00090    opnd_type            init_opnd;
00091    int                  ir_idx;
00092    int                  line;
00093    int                  list_idx;
00094    int                  opnd_column;
00095    int                  opnd_line;
00096    int                  sh_idx;
00097    int                  type_idx;
00098 
00099 
00100    TRACE (Func_Entry, "type_init_semantics", NULL);
00101 
00102    /* set comp_gen_expr to TRUE. This forces the fold of REAL   */
00103    /* constant expressions. When -Oieeeconform is specified,    */
00104    /* the folding of Real and Complex expressions is prevented. */
00105 
00106    comp_gen_expr = TRUE;
00107 
00108    ir_idx       = SH_IR_IDX(curr_stmt_sh_idx);
00109    attr_idx     = IR_IDX_L(ir_idx);
00110 
00111    COPY_OPND(init_opnd, IR_OPND_R(ir_idx));
00112 
00113    line = IR_LINE_NUM_L(ir_idx);
00114    col  = IR_COL_NUM_L(ir_idx);
00115 
00116    /* Constraint checks:                                                   */
00117    /* * A variable that is a member of blank common should not be          */
00118    /*   initialized.                                                       */
00119    /* * A variable that is a member of a named common block should only be */
00120    /*   initialized in a block data program unit.                          */
00121    /* * A variable that is a member of a task common block must not be     */
00122    /*   initialized.                                                       */
00123    /* * From a CF77 SPR:  If an object in a Block Data program unit is NOT */
00124    /*   in a common block (and is not equivalenced to an object in common) */
00125    /*   but IS initialized, issue a warning.                               */
00126 
00127    if (ATD_IN_COMMON(attr_idx)) {
00128 
00129       if (SB_BLK_TYPE(ATD_STOR_BLK_IDX(attr_idx)) == Common) {
00130 
00131          if (SB_BLANK_COMMON(ATD_STOR_BLK_IDX(attr_idx))) {
00132             PRINTMSG(line, 1109, Ansi, col);
00133          }
00134 
00135          else if (ATP_PGM_UNIT(SCP_ATTR_IDX(curr_scp_idx)) != Blockdata) {
00136 
00137 # if defined(_ALLOW_DATA_INIT_OF_COMMON)
00138             PRINTMSG(line, 692, Ansi, col);
00139 # else
00140             PRINTMSG(line, 1542, Warning, col);
00141 # endif
00142          }
00143       }
00144       else if (SB_BLK_TYPE(ATD_STOR_BLK_IDX(attr_idx)) == Task_Common) {
00145          PRINTMSG(line, 851, Error, col);
00146          goto EXIT;
00147       }
00148    }
00149    else if (ATP_PGM_UNIT(SCP_ATTR_IDX(curr_scp_idx)) == Blockdata  &&
00150             ! (ATD_EQUIV(attr_idx)  &&
00151                SB_IS_COMMON(ATD_STOR_BLK_IDX(attr_idx)))) {
00152       PRINTMSG(line, 825, Warning, col);
00153    }
00154 
00155    /* There is no way to initialize a CRI character pointer.               */
00156 
00157    type_idx = ATD_TYPE_IDX(attr_idx);
00158 
00159    if (TYP_TYPE(type_idx) == CRI_Ch_Ptr) {
00160       PRINTMSG(line, 695, Error, col);
00161       goto EXIT;
00162    }
00163 
00164    if (AT_DCL_ERR(attr_idx)) {
00165       /* don't do anything else */
00166       goto EXIT;
00167    }
00168 
00169 
00170    OPND_FLD(init_target_opnd) = AT_Tbl_Idx;
00171    OPND_IDX(init_target_opnd) = attr_idx;
00172    OPND_LINE_NUM(init_target_opnd) = line;
00173    OPND_COL_NUM(init_target_opnd) = col;
00174 
00175    target_array_idx             = ATD_ARRAY_IDX(attr_idx);
00176 
00177    if (TYP_TYPE(type_idx) == Integer ||
00178        TYP_TYPE(type_idx) == Real    ||
00179        TYP_TYPE(type_idx) == Complex) {
00180 
00181       check_type_conversion = TRUE;
00182       target_type_idx       = type_idx;
00183    }
00184    else if (TYP_TYPE(type_idx) == Character) {
00185 
00186       if (TYP_CHAR_CLASS(type_idx) == Const_Len_Char) {
00187 
00188          check_type_conversion = TRUE;
00189          target_type_idx       = Character_1;
00190          target_char_len_idx   = TYP_IDX(type_idx);
00191       }
00192    }
00193 
00194    expr_mode  = Initialization_Expr;
00195    xref_state = CIF_Symbol_Reference;
00196 
00197    if (expr_semantics(&init_opnd, &expr_desc)) {
00198 
00199       if (ATD_POINTER(attr_idx) &&
00200           (OPND_FLD(init_opnd) == AT_Tbl_Idx || 
00201            OPND_FLD(init_opnd) == CN_Tbl_Idx ||
00202            (OPND_FLD(init_opnd) == IR_Tbl_Idx &&
00203             IR_OPR(OPND_IDX(init_opnd)) != Null_Intrinsic_Opr))) {
00204          PRINTMSG(line, 1559, Error, col,
00205                   AT_OBJ_NAME_PTR(attr_idx));
00206          goto EXIT;
00207       }
00208 
00209       if (! expr_desc.foldable) {
00210 
00211          /* The initialization expression must be a constant. */
00212 
00213          if (ATD_POINTER(attr_idx) &&
00214              OPND_FLD(init_opnd) == IR_Tbl_Idx &&
00215              IR_OPR(OPND_IDX(init_opnd)) == Null_Intrinsic_Opr) {
00216              goto EXIT;
00217          }
00218          else {
00219             find_opnd_line_and_column(&init_opnd, &opnd_line, &opnd_column);
00220             PRINTMSG(opnd_line, 842, Error, opnd_column);
00221             goto EXIT;
00222          }
00223       }
00224 
00225       while (OPND_FLD(init_opnd) == IR_Tbl_Idx) {
00226         COPY_OPND(init_opnd, IR_OPND_L(OPND_IDX(init_opnd)));
00227       }
00228    }
00229    else {
00230       goto EXIT;
00231    }
00232 
00233    if (OPND_FLD(init_opnd) == AT_Tbl_Idx) {
00234 
00235       if (attr_init_semantics(&init_opnd, attr_idx, ir_idx, &expr_desc)) {
00236 
00237          /* pull this init out of stmts. don't need it any more */
00238 
00239          sh_idx                                 = curr_stmt_sh_idx;
00240          SH_NEXT_IDX(SH_PREV_IDX(sh_idx))       = SH_NEXT_IDX(sh_idx);
00241          SH_PREV_IDX(SH_NEXT_IDX(sh_idx))       = SH_PREV_IDX(sh_idx);
00242          curr_stmt_sh_idx                       = SH_PREV_IDX(sh_idx);
00243          FREE_IR_NODE(ir_idx);
00244          FREE_SH_NODE(sh_idx);
00245       }
00246    }
00247    else {
00248 
00249       if (const_init_semantics(&init_opnd, attr_idx, ir_idx)) {
00250          find_opnd_line_and_column(&init_opnd, &opnd_line, &opnd_column);
00251          NTR_IR_LIST_TBL(list_idx);
00252          IR_FLD_R(ir_idx)       = IL_Tbl_Idx;
00253          IR_IDX_R(ir_idx)       = list_idx;
00254          IR_LIST_CNT_R(ir_idx)  = 3;
00255  
00256          COPY_OPND(IL_OPND(list_idx), init_opnd);
00257        
00258          NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
00259          IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
00260          list_idx               = IL_NEXT_LIST_IDX(list_idx);
00261 
00262          IL_FLD(list_idx)       = CN_Tbl_Idx;
00263          IL_IDX(list_idx)       = CN_INTEGER_ONE_IDX;
00264          IL_LINE_NUM(list_idx)  = opnd_line;
00265          IL_COL_NUM(list_idx)   = opnd_column;
00266 
00267          NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
00268          IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
00269          list_idx               = IL_NEXT_LIST_IDX(list_idx);
00270 
00271          IL_FLD(list_idx)       = CN_Tbl_Idx;
00272          IL_IDX(list_idx)       = CN_INTEGER_ZERO_IDX;
00273          IL_LINE_NUM(list_idx)  = opnd_line;
00274          IL_COL_NUM(list_idx)   = opnd_column;
00275       }
00276    }
00277 
00278 EXIT:
00279 
00280    expr_mode                    = Regular_Expr;
00281    check_type_conversion        = FALSE;
00282    target_array_idx             = NULL_IDX;
00283    init_target_opnd             = null_opnd;
00284 
00285    /* reset comp_gen_expr to FALSE. end of compiler generated expression */
00286 
00287    comp_gen_expr = FALSE;
00288 
00289    TRACE (Func_Exit, "type_init_semantics", NULL);
00290 
00291    return;
00292 
00293 }  /* type_init_semantics */
00294 
00295 /******************************************************************************\
00296 |*                                                                            *|
00297 |* Description:                                                               *|
00298 |*      Do semantics for type declaration initializations.                    *|
00299 |*                                                                            *|
00300 |* Input parameters:                                                          *|
00301 |*      NONE                                                                  *|
00302 |*                                                                            *|
00303 |* Output parameters:                                                         *|
00304 |*      NONE                                                                  *|
00305 |*                                                                            *|
00306 |* Returns:                                                                   *|
00307 |*      NOTHING                                                               *|
00308 |*                                                                            *|
00309 \******************************************************************************/
00310 void default_init_semantics(int attr_idx)
00311 {
00312 
00313    int                  column;
00314    expr_arg_type        expr_desc;
00315    opnd_type            init_opnd;
00316    int                  line;
00317    int                  next_sh_idx;
00318    boolean              null_init;
00319    int                  old_curr_stmt_sh_idx;
00320    opnd_type            opnd;
00321    int                  sh_idx;
00322    int                  type_idx;
00323    int                  type_init_sh_idx;
00324 
00325 
00326    TRACE (Func_Entry, "default_init_semantics", NULL);
00327 
00328 # ifdef _DEBUG
00329    if (ATD_CPNT_INIT_IDX(attr_idx) == NULL_IDX ||
00330        ATD_FLD(attr_idx) != IR_Tbl_Idx ||
00331        (IR_OPR(ATD_CPNT_INIT_IDX(attr_idx)) != Init_Opr &&
00332         IR_OPR(ATD_CPNT_INIT_IDX(attr_idx)) != Null_Opr)) {
00333 
00334       PRINTMSG(AT_DEF_LINE(attr_idx), 626, Internal,
00335                AT_DEF_COLUMN(attr_idx),
00336                "Init_Opr or Null_Opr", "default_init_semantics");
00337    }
00338 # endif
00339 
00340    /* Generate a type init statement so that expression semantics gets */
00341    /* anything it generates in the correct order.  This statement will */
00342    /* be removed.                                                      */
00343 
00344    old_curr_stmt_sh_idx = curr_stmt_sh_idx;
00345 
00346    gen_sh(After,
00347           Type_Init_Stmt,
00348           AT_DEF_LINE(attr_idx),
00349           AT_DEF_COLUMN(attr_idx),
00350           FALSE,
00351           FALSE,
00352           TRUE);
00353 
00354    type_init_sh_idx     = curr_stmt_sh_idx;
00355    target_array_idx     = ATD_ARRAY_IDX(attr_idx);
00356    type_idx             = ATD_TYPE_IDX(attr_idx);
00357    null_init            = FALSE;
00358 
00359    if (TYP_TYPE(type_idx) == Integer ||
00360        TYP_TYPE(type_idx) == Real    ||
00361        TYP_TYPE(type_idx) == Complex) {
00362       check_type_conversion = TRUE;
00363       target_type_idx       = type_idx;
00364    }
00365    else if (TYP_TYPE(type_idx) == Character) {
00366 
00367       if (TYP_CHAR_CLASS(type_idx) == Const_Len_Char) {
00368          check_type_conversion = TRUE;
00369          target_type_idx       = Character_1;
00370          target_char_len_idx   = TYP_IDX(type_idx);
00371       }
00372    }
00373 
00374    expr_mode            = Initialization_Expr;
00375    xref_state           = CIF_Symbol_Reference;
00376    expr_desc.rank       = 0;
00377 
00378    COPY_OPND(init_opnd, IR_OPND_R(ATD_CPNT_INIT_IDX(attr_idx)));
00379 
00380    if (expr_semantics(&init_opnd, &expr_desc)) {
00381 
00382       if (ATD_POINTER(attr_idx) &&
00383           (OPND_FLD(init_opnd) == AT_Tbl_Idx || 
00384            OPND_FLD(init_opnd) == CN_Tbl_Idx ||
00385            (OPND_FLD(init_opnd) == IR_Tbl_Idx &&
00386             IR_OPR(OPND_IDX(init_opnd)) != Null_Intrinsic_Opr))) {
00387          find_opnd_line_and_column(&init_opnd, &line, &column);
00388          PRINTMSG(line, 1559, Error, column, AT_OBJ_NAME_PTR(attr_idx));
00389          AT_DCL_ERR(attr_idx)           = TRUE;
00390          goto EXIT;
00391       }
00392 
00393       if (!expr_desc.foldable) {
00394 
00395          /* The initialization expression must be a constant. */
00396 
00397          if (ATD_POINTER(attr_idx) &&
00398              OPND_FLD(init_opnd) == IR_Tbl_Idx &&
00399              IR_OPR(OPND_IDX(init_opnd)) == Null_Intrinsic_Opr) {
00400 
00401             /* Pointer components are null'd by default, so we  */
00402             /* do not need to keep the null information around. */
00403 
00404             null_init   = TRUE;
00405             goto EXIT;
00406          }
00407 
00408          find_opnd_line_and_column(&init_opnd, &line, &column);
00409          PRINTMSG(line, 842, Error, column);
00410          AT_DCL_ERR(attr_idx)   = TRUE;
00411       }
00412 
00413       /* The assumption is that if this is IR, we will    */
00414       /* never end up with a CN_Tbl_Idx on the left side. */
00415 
00416       if (OPND_FLD(init_opnd) == CN_Tbl_Idx) {
00417 
00418          if (!const_init_semantics(&init_opnd,
00419                                     attr_idx,
00420                                     ATD_CPNT_INIT_IDX(attr_idx))) {
00421             AT_DCL_ERR(attr_idx) = TRUE;
00422          }
00423       }
00424       else {
00425          COPY_OPND(opnd, init_opnd);
00426 
00427          while (OPND_FLD(opnd) == IR_Tbl_Idx && OPND_IDX(opnd) != NULL_IDX) {
00428            COPY_OPND(opnd, IR_OPND_L(OPND_IDX(opnd)));
00429          }
00430 
00431          if (OPND_FLD(opnd) == AT_Tbl_Idx) {
00432 
00433             if (!attr_init_semantics(&opnd,
00434                                      attr_idx, 
00435                                      ATD_CPNT_INIT_IDX(attr_idx),
00436                                     &expr_desc)) {
00437                AT_DCL_ERR(attr_idx) = TRUE;
00438             }
00439          }
00440          else {
00441             PRINTMSG(AT_DEF_LINE(attr_idx), 626, Internal,
00442                      AT_DEF_COLUMN(attr_idx), 
00443                      "AT_Tbl_Idx",
00444                      "default_init_semantics");
00445          }
00446       }
00447    }
00448    else {  /* The initialization expression has an error */
00449       AT_DCL_ERR(attr_idx) = TRUE;
00450    }
00451 
00452 EXIT:
00453 
00454    expr_mode                    = Regular_Expr;
00455    check_type_conversion        = FALSE;
00456    target_array_idx             = NULL_IDX;
00457    sh_idx                       = SH_NEXT_IDX(old_curr_stmt_sh_idx);
00458 
00459    if (old_curr_stmt_sh_idx != NULL_IDX) {
00460       SH_NEXT_IDX(old_curr_stmt_sh_idx) = SH_NEXT_IDX(type_init_sh_idx);
00461    }
00462 
00463    if (SH_NEXT_IDX(type_init_sh_idx) != NULL_IDX) {
00464       SH_PREV_IDX(SH_NEXT_IDX(type_init_sh_idx)) = old_curr_stmt_sh_idx;
00465    }
00466 
00467    curr_stmt_sh_idx = old_curr_stmt_sh_idx;
00468 
00469    while (sh_idx != type_init_sh_idx) {
00470       next_sh_idx       = SH_NEXT_IDX(sh_idx);
00471       FREE_SH_NODE(sh_idx);
00472       sh_idx            = next_sh_idx;
00473       
00474    }
00475 
00476    FREE_SH_NODE(type_init_sh_idx);
00477 
00478    if (AT_DCL_ERR(attr_idx) || null_init) {
00479       ATD_CPNT_INIT_IDX(attr_idx) = NULL_IDX;
00480       ATD_FLD(attr_idx)           = NO_Tbl_Idx;
00481    }
00482    else {
00483       ATD_CPNT_INIT_IDX(attr_idx) = OPND_IDX(init_opnd);
00484       ATD_FLD(attr_idx)           = OPND_FLD(init_opnd);
00485    }
00486 
00487    TRACE (Func_Exit, "default_init_semantics", NULL);
00488 
00489    return;
00490 
00491 }  /* default_init_semantics */
00492 
00493 
00494 /******************************************************************************\
00495 |*                                                                            *|
00496 |* Description:                                                               *|
00497 |*      Do semantics for type declaration initializations.                    *|
00498 |*                                                                            *|
00499 |* Input parameters:                                                          *|
00500 |*      NONE                                                                  *|
00501 |*                                                                            *|
00502 |* Output parameters:                                                         *|
00503 |*      NONE                                                                  *|
00504 |*                                                                            *|
00505 |* Returns:                                                                   *|
00506 |*      NOTHING                                                               *|
00507 |*                                                                            *|
00508 \******************************************************************************/
00509 
00510 static  boolean attr_init_semantics(opnd_type           *init_opnd,
00511                                     int                  attr_idx,
00512                                     int                  ir_idx,
00513                                     expr_arg_type       *expr_desc)
00514 
00515 {
00516    int                  c_type_idx;
00517    int                  column;
00518    int                  i;
00519    int                  line;
00520    boolean              ok              = TRUE;
00521    int                  opnd_column;
00522    int                  opnd_line;
00523    char                 type_str[40];
00524 
00525 
00526    TRACE (Func_Entry, "attr_init_semantics", NULL);
00527 
00528    line         = IR_LINE_NUM_L(ir_idx);
00529    column       = IR_COL_NUM_L(ir_idx);
00530    c_type_idx   = expr_desc->type_idx;
00531 
00532    find_opnd_line_and_column(init_opnd, &opnd_line, &opnd_column);
00533 
00534    if (TYP_LINEAR(c_type_idx) == Long_Typeless) {
00535       PRINTMSG(opnd_line, 1133, Error, opnd_column);
00536       ok = FALSE;
00537    }
00538    else if (!check_asg_semantics(ATD_TYPE_IDX(attr_idx),
00539                                  c_type_idx,
00540                                  opnd_line,
00541                                  opnd_column)) {
00542       type_str[0] = '\0';
00543       strcat(type_str, get_basic_type_str(ATD_TYPE_IDX(attr_idx)));
00544 
00545       PRINTMSG(line, 843, Error, column, AT_OBJ_NAME_PTR(attr_idx),
00546                type_str,
00547                get_basic_type_str(c_type_idx));
00548       ok = FALSE;
00549    }
00550    else if (expr_desc->rank > 0) {         /* check array conformance */
00551 
00552       if (ATD_ARRAY_IDX(attr_idx) == NULL_IDX) {
00553          PRINTMSG(line, 844, Error, column, AT_OBJ_NAME_PTR(attr_idx));
00554          ok = FALSE;
00555       }
00556       else if (expr_desc->rank == BD_RANK(ATD_ARRAY_IDX(attr_idx))) {
00557 
00558          for (i = 1; i <= expr_desc->rank; i++) {
00559 
00560             if (fold_relationals(expr_desc->shape[i-1].idx,
00561                                  BD_XT_IDX(ATD_ARRAY_IDX(attr_idx),i),
00562                                  Ne_Opr)) {
00563 
00564                PRINTMSG(line, 845, Error, column, AT_OBJ_NAME_PTR(attr_idx));
00565                ok = FALSE;
00566                break;
00567             }
00568          }
00569       }
00570       else {
00571          PRINTMSG(line, 845, Error, column, AT_OBJ_NAME_PTR(attr_idx));
00572          ok = FALSE;
00573       }
00574    }
00575 
00576    TRACE (Func_Exit, "attr_init_semantics", NULL);
00577 
00578    return(ok);
00579 
00580 }  /* attr_init_semantics */
00581 
00582 /******************************************************************************\
00583 |*                                                                            *|
00584 |* Description:                                                               *|
00585 |*      Do semantics for type declaration initializations.                    *|
00586 |*                                                                            *|
00587 |* Input parameters:                                                          *|
00588 |*      NONE                                                                  *|
00589 |*                                                                            *|
00590 |* Output parameters:                                                         *|
00591 |*      NONE                                                                  *|
00592 |*                                                                            *|
00593 |* Returns:                                                                   *|
00594 |*      NOTHING                                                               *|
00595 |*                                                                            *|
00596 \******************************************************************************/
00597 
00598 static boolean const_init_semantics(opnd_type           *init_opnd,
00599                                     int                  attr_idx,
00600                                     int                  ir_idx)
00601 
00602 {
00603    int                  a_type_idx;
00604    long_type            another_constant[MAX_WORDS_FOR_NUMERIC];
00605    int                  c_type_idx;
00606    char                 *char_ptr;
00607    char                 *c_char_ptr;
00608    int                  column;
00609    int                  const_idx;
00610    long64               i;
00611    int                  line;
00612    boolean              ok              = TRUE;
00613    int                  opnd_column;
00614    int                  opnd_line;
00615    opnd_type            tar_opnd;
00616    char                 type_str[40];
00617 
00618 
00619    TRACE (Func_Entry, "const_init_semantics", NULL);
00620 
00621    line         = IR_LINE_NUM_L(ir_idx);
00622    column       = IR_COL_NUM_L(ir_idx);
00623    a_type_idx   = ATD_TYPE_IDX(attr_idx);
00624    c_type_idx   = CN_TYPE_IDX(OPND_IDX((*init_opnd)));
00625 
00626    find_opnd_line_and_column(init_opnd, &opnd_line, &opnd_column);
00627 
00628    if (TYP_LINEAR(c_type_idx) == Long_Typeless) {
00629       PRINTMSG(opnd_line, 1133, Error, opnd_column);
00630       ok = FALSE;
00631       goto EXIT;
00632    }
00633    else if (!check_asg_semantics(a_type_idx,
00634                                  c_type_idx,
00635                                  opnd_line,
00636                                  opnd_column)) {
00637       type_str[0] = '\0';
00638       strcat(type_str, get_basic_type_str(a_type_idx));
00639 
00640       PRINTMSG(line, 843, Error, column, AT_OBJ_NAME_PTR(attr_idx),
00641                type_str,
00642                get_basic_type_str(c_type_idx));
00643       ok = FALSE;
00644       goto EXIT;
00645    }
00646 
00647    if (TYP_TYPE(a_type_idx) == Character) {
00648 
00649       if (fold_relationals(TYP_IDX(a_type_idx),
00650                            TYP_IDX(c_type_idx),
00651                            Ne_Opr)) {
00652 
00653          /* assumes that these are both CN_Tbl_Idx */
00654 
00655          /* create new constant for the right length and put the */
00656          /* original string in it. Truncate or blank pad to fit. */
00657 
00658          const_idx      = ntr_const_tbl(a_type_idx, TRUE, NULL);
00659          char_ptr       = (char *)&CN_CONST(const_idx);
00660          c_char_ptr     = (char *)&CN_CONST(OPND_IDX((*init_opnd)));
00661 
00662          for (i = 0; i < CN_INT_TO_C(TYP_IDX(a_type_idx)); i++) {
00663             char_ptr[i] = (i >= CN_INT_TO_C(TYP_IDX(c_type_idx))) ?
00664                           ' ' : c_char_ptr[i];
00665          }
00666 
00667          while (i % TARGET_CHARS_PER_WORD != 0) {
00668             char_ptr[i] = ' ';
00669             i++;
00670          }
00671 
00672          OPND_IDX((*init_opnd)) = const_idx;
00673       }
00674 
00675       /* If this is default initialization, the substring reference will */
00676       /* need to be generated when something is actually initialized.    */
00677 
00678       if (ATD_CLASS(attr_idx) != Struct_Component) {
00679          COPY_OPND(tar_opnd, IR_OPND_L(ir_idx));
00680 
00681          if (gen_whole_substring(&tar_opnd, 0)) {
00682             COPY_OPND(IR_OPND_L(ir_idx), tar_opnd);
00683          }
00684       }
00685    }
00686    else if (TYP_TYPE(c_type_idx) == Character ||
00687             TYP_TYPE(c_type_idx) == Typeless) {
00688 
00689       /* cast the character or typeless constant to the target type */
00690 
00691       OPND_IDX((*init_opnd)) = cast_typeless_constant(OPND_IDX((*init_opnd)),
00692                                                       a_type_idx,
00693                                                       opnd_line,
00694                                                       opnd_column);
00695    }
00696    else if (TYP_TYPE(c_type_idx) != Character  &&
00697             TYP_TYPE(c_type_idx) != Typeless   &&
00698             TYP_LINEAR(c_type_idx) != TYP_LINEAR(a_type_idx)) {
00699 
00700       /* PDGCS does not like it if the value is not the same size as the   */
00701       /* target; for example, the value is a double precision constant and */
00702       /* the target is a single precision variable.  So explicitly convert */
00703       /* the value to the type and kind type parameter of the target for   */
00704       /* all combinations to be consistent.                                */
00705 
00706       if (folder_driver( (char *) &CN_CONST(OPND_IDX((*init_opnd))),
00707                          c_type_idx,
00708                          NULL,
00709                          NULL_IDX,
00710                          another_constant,
00711                         &a_type_idx,
00712                          opnd_line,
00713                          opnd_column,
00714                          1,
00715                          Cvrt_Opr)) {
00716 
00717          OPND_IDX((*init_opnd)) = ntr_const_tbl(ATD_TYPE_IDX(attr_idx),
00718                                                 FALSE,
00719                                                 another_constant);
00720       }
00721    }
00722 
00723 EXIT:
00724 
00725    TRACE (Func_Exit, "const_init_semantics", NULL);
00726 
00727    return(ok);
00728 
00729 }  /* const_init_semantics */
00730 
00731 /******************************************************************************\
00732 |*                                                                            *|
00733 |* Description:                                                               *|
00734 |*      This routine creates a chain of stmts to handle default initialization*|
00735 |*      of a component or components.                                         *|
00736 |*                                                                            *|
00737 |* Input parameters:                                                          *|
00738 |*      attr_idx - idx of variable to process.                                *|
00739 |*                                                                            *|
00740 |* Output parameters:                                                         *|
00741 |*      NONE                                                                  *|
00742 |*                                                                            *|
00743 |* Returns:                                                                   *|
00744 |*      NOTHING                                                               *|
00745 |*                                                                            *|
00746 \******************************************************************************/
00747 
00748 void gen_default_init_code(int   attr_idx)
00749 
00750 {
00751    expr_arg_type        expr_desc;
00752    operator_type        operator;
00753    opnd_type            opnd;
00754 
00755 
00756    TRACE (Func_Entry, "gen_default_init_code", NULL);
00757 
00758    if (AT_DCL_ERR(attr_idx)) {
00759       goto EXIT;
00760    }
00761 
00762    if (SB_RUNTIME_INIT(ATD_STOR_BLK_IDX(attr_idx))) {
00763 
00764       /* The var is on the stack, or is automatic, a darg or a func  */
00765       /* result.  Generate runtime code for the initialization.      */
00766 
00767       operator = Asg_Opr;
00768    }
00769    else if (ATD_IN_COMMON(attr_idx)) {
00770       operator = Init_Opr;
00771 
00772 # if 0
00773 # if defined(_TARGET_OS_SOLARIS) || (defined(_TARGET_OS_IRIX) || defined(_TARGET_OS_LINUX))
00774       func = gen_common_dv_init;
00775 # else
00776       func = gen_static_dv_whole_def;
00777 # endif
00778 # endif
00779    }
00780    else {
00781       operator = Init_Opr;
00782    }
00783 
00784    if (!ATD_IM_A_DOPE(attr_idx) &&
00785        TYP_TYPE(ATD_TYPE_IDX(attr_idx)) == Structure           &&
00786        ATT_DEFAULT_INITIALIZED(TYP_IDX(ATD_TYPE_IDX(attr_idx))) &&
00787        !AT_DCL_ERR(TYP_IDX(ATD_TYPE_IDX(attr_idx)))) {
00788 
00789       OPND_FLD(opnd)      = AT_Tbl_Idx;
00790       OPND_IDX(opnd)      = attr_idx;
00791       OPND_LINE_NUM(opnd) = AT_DEF_LINE(attr_idx);
00792       OPND_COL_NUM(opnd)  = AT_DEF_COLUMN(attr_idx);
00793 
00794 # if defined(COARRAY_FORTRAN)
00795       if (ATD_ARRAY_IDX(attr_idx) || ATD_PE_ARRAY_IDX(attr_idx)) {
00796 # else
00797       if (ATD_ARRAY_IDX(attr_idx)) {
00798 # endif
00799          gen_whole_subscript(&opnd, &expr_desc);
00800       }
00801 
00802       process_all_initialized_cpnts(&opnd, 
00803                                     TYP_IDX(ATD_TYPE_IDX(attr_idx)),
00804                                     operator);
00805    }
00806 
00807 EXIT:
00808 
00809    TRACE (Func_Exit, "gen_default_init_code", NULL);
00810 
00811    return;
00812 
00813 }  /* gen_default_init_code */
00814 
00815 /******************************************************************************\
00816 |*                                                                            *|
00817 |* Description:                                                               *|
00818 |*      recursively go through all components of a structure to look for      *|
00819 |*      default initialization. Then call the supplied routine func for       *|
00820 |*      processing.                                                           *|
00821 |*                                                                            *|
00822 |* Input parameters:                                                          *|
00823 |*      left_opnd - current base of sub-object reference.                     *|
00824 |*      type_idx  - defined type attr.                                        *|
00825 |*      operator  - Whether to use Init_Opr or Asg_Opr.                       *|
00826 |*                                                                            *|
00827 |* Output parameters:                                                         *|
00828 |*      NONE                                                                  *|
00829 |*                                                                            *|
00830 |* Returns:                                                                   *|
00831 |*      NOTHING                                                               *|
00832 |*                                                                            *|
00833 \******************************************************************************/
00834 
00835 static void process_all_initialized_cpnts(opnd_type    *left_opnd,
00836                                           int           type_idx,
00837                                           operator_type operator)
00838 
00839 {
00840    int                  attr_idx;
00841    expr_arg_type        expr_desc;
00842    opnd_type            expr_opnd;
00843    int                  init_idx;
00844    int                  ir_idx;
00845    int                  list_idx;
00846    opnd_type            opnd;
00847    int                  sn_idx;
00848 
00849 
00850    TRACE (Func_Entry, "process_all_initialized_cpnts", NULL);
00851 
00852    sn_idx = ATT_FIRST_CPNT_IDX(type_idx);
00853 
00854    while (sn_idx != NULL_IDX) {
00855       attr_idx = SN_ATTR_IDX(sn_idx);  /* A component */
00856 
00857       if (ATD_CPNT_INIT_IDX(attr_idx) != NULL_IDX) {
00858          NTR_IR_TBL(ir_idx);
00859 
00860          IR_OPR(ir_idx)         = Struct_Opr;
00861          IR_TYPE_IDX(ir_idx)    = ATD_TYPE_IDX(attr_idx);
00862          IR_LINE_NUM(ir_idx)    = AT_DEF_LINE(attr_idx);
00863          IR_COL_NUM(ir_idx)     = AT_DEF_COLUMN(attr_idx);
00864 
00865          COPY_OPND(IR_OPND_L(ir_idx), (*left_opnd));
00866 
00867          IR_FLD_R(ir_idx)       = AT_Tbl_Idx;
00868          IR_IDX_R(ir_idx)       = attr_idx;
00869          IR_LINE_NUM_R(ir_idx)  = AT_DEF_LINE(attr_idx);
00870          IR_COL_NUM_R(ir_idx)   = AT_DEF_COLUMN(attr_idx);
00871 
00872          if (IR_FLD_L(ir_idx) == IR_Tbl_Idx) {
00873              IR_RANK(ir_idx)    = IR_RANK(IR_IDX_L(ir_idx));
00874          }
00875 
00876          NTR_IR_TBL(init_idx);
00877 
00878          IR_OPR(init_idx)       = operator;
00879          IR_LINE_NUM(init_idx)  = AT_DEF_LINE(attr_idx);
00880          IR_COL_NUM(init_idx)   = AT_DEF_COLUMN(attr_idx);
00881          IR_TYPE_IDX(init_idx)  = TYPELESS_DEFAULT_TYPE;
00882          IR_FLD_L(init_idx)     = IR_Tbl_Idx;
00883          IR_IDX_L(init_idx)     = ir_idx;
00884          IR_LINE_NUM_L(init_idx)= AT_DEF_LINE(attr_idx);
00885          IR_COL_NUM_L(init_idx) = AT_DEF_COLUMN(attr_idx);
00886 
00887          if (operator == Asg_Opr) {
00888 
00889             if (ATD_FLD(attr_idx) == IR_Tbl_Idx) {
00890 
00891                /* This should be an Init_Opr */
00892 
00893                if (IR_OPR(ATD_CPNT_INIT_IDX(attr_idx)) != Init_Opr) {
00894                   PRINTMSG(AT_DEF_LINE(attr_idx), 626, Internal,
00895                            AT_DEF_COLUMN(attr_idx),
00896                            "An Init Opr",
00897                            "process_all_initialized_cpnts");
00898                }
00899 
00900                COPY_OPND(IR_OPND_R(init_idx),
00901                          IL_OPND(IR_IDX_R(ATD_CPNT_INIT_IDX(attr_idx))));
00902             }
00903             else {
00904                IR_IDX_R(init_idx)       = ATD_CPNT_INIT_IDX(attr_idx);
00905                IR_FLD_R(init_idx)       = (fld_type) ATD_FLD(attr_idx);
00906                IR_LINE_NUM_R(init_idx)  = AT_DEF_LINE(attr_idx);
00907                IR_COL_NUM_R(init_idx)   = AT_DEF_COLUMN(attr_idx);
00908             }
00909 
00910             if (ATD_ARRAY_IDX(attr_idx) != NULL_IDX ||
00911                 TYP_TYPE(ATD_TYPE_IDX(attr_idx)) == Character) {   
00912                xref_state               = CIF_No_Usage_Rec;
00913                expr_desc.rank           = 0;
00914                OPND_FLD(expr_opnd)      = IR_Tbl_Idx;
00915                OPND_IDX(expr_opnd)      = ir_idx;;
00916 
00917                if (expr_semantics(&expr_opnd, &expr_desc)) {
00918                   COPY_OPND(IR_OPND_L(init_idx), expr_opnd);
00919                }
00920             }
00921 
00922             gen_sh(After,
00923                    Assignment_Stmt,
00924                    AT_DEF_LINE(attr_idx),
00925                    AT_DEF_COLUMN(attr_idx),
00926                    FALSE,
00927                    FALSE,
00928                    TRUE);
00929          }
00930          else {  /* Init_Opr */
00931 
00932             if (ATD_FLD(attr_idx) == IR_Tbl_Idx) {
00933 
00934                /* This should be an Init_Opr */
00935 
00936                if (IR_OPR(ATD_CPNT_INIT_IDX(attr_idx)) != Init_Opr) {
00937                   PRINTMSG(AT_DEF_LINE(attr_idx), 626, Internal,
00938                            AT_DEF_COLUMN(attr_idx),
00939                            "An Init Opr",
00940                            "process_all_initialized_cpnts");
00941                }
00942 
00943                IR_FLD_R(init_idx)       = IL_Tbl_Idx;
00944                IR_IDX_R(init_idx)       = IR_IDX_R(ATD_CPNT_INIT_IDX(attr_idx));
00945                IR_LIST_CNT_R(init_idx)  = 3;
00946             }
00947             else {
00948                NTR_IR_LIST_TBL(list_idx);
00949                IR_FLD_R(init_idx)       = IL_Tbl_Idx;
00950                IR_IDX_R(init_idx)       = list_idx;
00951                IR_LIST_CNT_R(init_idx)  = 3;
00952                IL_IDX(list_idx)         = ATD_CPNT_INIT_IDX(attr_idx);
00953                IL_FLD(list_idx)         = (fld_type) ATD_FLD(attr_idx);
00954                IL_LINE_NUM(list_idx)    = AT_DEF_LINE(attr_idx);
00955                IL_COL_NUM(list_idx)     = AT_DEF_COLUMN(attr_idx);
00956        
00957                NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
00958 
00959                IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
00960 
00961                list_idx                 = IL_NEXT_LIST_IDX(list_idx);
00962                IL_FLD(list_idx)         = CN_Tbl_Idx;
00963                IL_IDX(list_idx)         = CN_INTEGER_ONE_IDX;
00964                IL_LINE_NUM(list_idx)    = AT_DEF_LINE(attr_idx);
00965                IL_COL_NUM(list_idx)     = AT_DEF_COLUMN(attr_idx);
00966 
00967                NTR_IR_LIST_TBL(IL_NEXT_LIST_IDX(list_idx));
00968 
00969                IL_PREV_LIST_IDX(IL_NEXT_LIST_IDX(list_idx)) = list_idx;
00970 
00971                list_idx                 = IL_NEXT_LIST_IDX(list_idx);
00972                IL_FLD(list_idx)         = CN_Tbl_Idx;
00973                IL_IDX(list_idx)         = CN_INTEGER_ZERO_IDX;
00974                IL_LINE_NUM(list_idx)    = AT_DEF_LINE(attr_idx);
00975                IL_COL_NUM(list_idx)     = AT_DEF_COLUMN(attr_idx);
00976             }
00977 
00978             gen_sh(After,
00979                    Type_Init_Stmt,
00980                    AT_DEF_LINE(attr_idx),
00981                    AT_DEF_COLUMN(attr_idx),
00982                    FALSE,
00983                    FALSE,
00984                    TRUE);
00985          }
00986 
00987          SH_P2_SKIP_ME(curr_stmt_sh_idx) = TRUE;
00988          SH_IR_IDX(curr_stmt_sh_idx)     = init_idx;
00989       }
00990       else if (TYP_TYPE(ATD_TYPE_IDX(attr_idx)) == Structure           &&
00991                ATT_DEFAULT_INITIALIZED(TYP_IDX(ATD_TYPE_IDX(attr_idx)))) {
00992 
00993          NTR_IR_TBL(ir_idx);
00994          IR_OPR(ir_idx)         = Struct_Opr;
00995          IR_TYPE_IDX(ir_idx)    = ATD_TYPE_IDX(attr_idx);
00996          IR_LINE_NUM(ir_idx)    = AT_DEF_LINE(attr_idx);
00997          IR_COL_NUM(ir_idx)     = AT_DEF_COLUMN(attr_idx);
00998 
00999          COPY_OPND(IR_OPND_L(ir_idx), (*left_opnd));
01000 
01001          IR_FLD_R(ir_idx)       = AT_Tbl_Idx;
01002          IR_IDX_R(ir_idx)       = attr_idx;
01003          IR_LINE_NUM_R(ir_idx)  = AT_DEF_LINE(attr_idx);
01004          IR_COL_NUM_R(ir_idx)   = AT_DEF_COLUMN(attr_idx);
01005          OPND_FLD(opnd)         = IR_Tbl_Idx;
01006          OPND_IDX(opnd)         = ir_idx;
01007 
01008          if (IR_FLD_L(ir_idx) == IR_Tbl_Idx) {
01009              IR_RANK(ir_idx)    = IR_RANK(IR_IDX_L(ir_idx));
01010          }
01011 
01012          if (ATD_ARRAY_IDX(attr_idx) != NULL_IDX) {
01013             gen_whole_subscript(&opnd, &expr_desc);
01014          }
01015 
01016          process_all_initialized_cpnts(&opnd, 
01017                                        TYP_IDX(ATD_TYPE_IDX(attr_idx)),
01018                                        operator);
01019 
01020       }
01021 
01022       sn_idx = SN_SIBLING_LINK(sn_idx);
01023    }
01024 
01025    TRACE (Func_Exit, "process_all_initialized_cpnts", NULL);
01026 
01027    return;
01028 
01029 }  /* process_all_initialized_cpnts */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines