Changeset 131

Show
Ignore:
Timestamp:
12/26/06 21:16:22 (2 years ago)
Author:
ant_39
Message:
  • Cleanups in labels and goto handling.
  • Labels at program block are now forbidden (because there is no enclosing begin-end block that would hold them, standard seems to imply it).
  • Labels are stored to the most enclosing *block*, not most enclosing compound of any kind. An exception is in effect that allows the label to be stored at program block, even if it is actually compound statement, and not block.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gcc/gcc/algol60/lang.c

    r104 r131  
    250250 
    251251  // toplev 'begin'-'end' block is the body of `main' 
    252   statement_t * stmt0 = slist_front (container_stmts (as_container (ast))); 
     252  //statement_t * stmt0 = slist_front (container_stmts (as_container (ast))); 
    253253 
    254254  al60l_bind_state_t * state = new_bind_state (); 
    255255  bind_state_push_function (state, resultdecl, decl); 
    256256  { 
    257     tree bind = stmt_build_generic (stmt0, state); 
     257    tree bind = stmt_build_generic (ast, state); 
    258258 
    259259    // add fallback return to the body 
  • trunk/gcc/gcc/algol60/parser.y

    r130 r131  
    3333  slist_t * blockstack; 
    3434  container_t * block; 
     35  container_t * program_block; 
    3536  estring_t * tmp; 
    3637} parser_rep_t; 
     
    236237    { 
    237238      log_printf (parser->log, ll_debug, "Program -> LabelList Block SEPSEMICOLON EOFTOK"); 
    238       private_dump_log_labels (parser, $2); 
    239       private_add_labels_to_symtab (parser, parser->block, $2, $3); 
    240239      container_add_stmt (parser->block, $3); 
    241       parser->result = as_statement (private_close_block (parser)); 
     240      if (!slist_empty ($2)) 
     241        log_printfc (parser->log, ll_error, cr_csr (parser, &@3), 
     242                     "labels not allowed at program block."); 
     243      private_close_block (parser); // toplev 
     244      private_close_block (parser); // dummy 
     245      parser->result = as_statement (parser->program_block); 
    242246      YYACCEPT; 
    243247    } 
     
    292296Block: 
    293297  KWBEGIN 
    294   { private_open_block (parser, new_stmt_block (NULL));} 
     298  { 
     299    container_t * c = new_stmt_block (cr_csr (parser, &@1)); 
     300    container_set_parent (c, parser->block); 
     301    private_open_block (parser, c); 
     302    if (parser->program_block == NULL) 
     303      { 
     304        log_printf (parser->log, ll_debug, "  %p is program block", c); 
     305        parser->program_block = c; 
     306      } 
     307  } 
    295308  BlockDeclarationsList StatementList 
    296309  KWEND 
     
    418431 
    419432OptOwn: 
    420   /*eps*/ { $$ = 0; } 
     433  /*epsilon*/ { $$ = 0; } 
    421434  | 
    422435  KWOWN   { $$ = 1; @$ = @1; } 
    423436 
    424437OptIntrinsicType: 
    425   /* epsilon */ 
     438  /*epsilon*/ 
    426439    { 
    427440      log_printf (parser->log, ll_debug, "OptIntrinsicType -> epsilon"); 
     
    498511 
    499512OptBoundsPairList: 
    500   /* epsilon */ 
     513  /*epsilon*/ 
    501514    { 
    502515      log_printf (parser->log, ll_debug, "OptBoundsPairList -> epsilon"); 
     
    857870 
    858871BasicStatement: 
    859   /* eps */ 
     872  /*epsilon*/ 
    860873    { 
    861874      log_printf (parser->log, ll_debug, "BasicStatement -> LabelList"); 
     
    965978 
    966979OptElseClause: 
    967   /* eps */ 
     980  /*epsilon*/ 
    968981    { 
    969982      $$ = NULL; 
     
    10461059      guard_ptr (buf, 1, ret->blockstack = new_slist ()); 
    10471060      guard_ptr (buf, 1, ret->tmp = new_estring ()); 
     1061      ret->program_block = NULL; 
    10481062      return (void*)ret; 
    10491063    } 
     
    11241138 
    11251139static void 
    1126 private_add_labels_to_symtab (parser_rep_t * parser ATTRIBUTE_UNUSED
    1127                               container_t * cont
     1140private_add_labels_to_symtab (parser_rep_t * parser
     1141                              container_t * context
    11281142                              slist_t * slist, statement_t * target) 
    11291143{ 
     1144  // Algol has an interesting quirk: labels are local to the nearest 
     1145  // enclosing *block* (as opposed to mere compound statement).  So we 
     1146  // must actually look up nearest block with declarations. 
     1147  // 
     1148  // Strictly speaking, when there are no declarations at program 
     1149  // block, then it's actually program compound statement, and no 
     1150  // labels may be defined at that level.  However we will put all 
     1151  // labels to the program block, if no other block is closer. 
     1152 
     1153  while (context != parser->program_block 
     1154         && slist_empty (container_symtab (context))) 
     1155    context = container_parent (context); 
     1156 
    11301157  slist_it_t * it = slist_iter (slist); 
    11311158  for (; slist_it_has (it); slist_it_next (it)) 
     
    11331160      label_t * lbl = slist_it_get (it); 
    11341161      symbol_t * sym = new_symbol (lbl); 
    1135       container_add_symbol (cont, sym, sek_ordinary); 
    1136       symbol_set_stmt (sym, target); 
    1137       symbol_set_type (sym, type_label ()); 
    1138       stmt_add_label (target, sym); 
     1162      if (container_add_symbol (context, sym, sek_ordinary) != 0) 
     1163        { 
     1164          cursor_t * csr = stmt_cursor (target); 
     1165          log_printfc (parser->log, ll_error, csr, 
     1166                       "duplicate label `%s'.", estr_cstr (label_id (lbl))); 
     1167          delete_symbol (sym); 
     1168        } 
     1169      else 
     1170        { 
     1171          symbol_set_stmt (sym, target); 
     1172          symbol_set_type (sym, type_label ()); 
     1173          stmt_add_label (target, sym); 
     1174        } 
    11391175    } 
    11401176  delete_slist_it (it); 
     
    11461182  assert (cont != NULL); 
    11471183  slist_pushfront (parser->blockstack, parser->block); 
     1184  log_printf (parser->log, ll_debug, "open %p", cont); 
    11481185  parser->block = cont; 
    11491186} 
     
    11551192  container_t * cont = parser->block; 
    11561193  parser->block = slist_popfront (parser->blockstack); 
     1194  log_printf (parser->log, ll_debug, "close %p", cont); 
    11571195  return cont; 
    11581196} 
  • trunk/gcc/gcc/testsuite/algol60.dg/fail/labels1.a60

    r87 r131  
    11'comment' { dg-do compile } ; 
    22label1: 
    3 label2: 
    4 'begin' 
     3'begin' 'comment' { dg-error "label" } ; 
    54        label3: ; 
    65        label4: label5: