Changeset 170

Show
Ignore:
Timestamp:
05/12/07 19:33:47 (1 year ago)
Author:
ant_39
Message:
  • Second resolution is now done locally in expression.c, no need to have direct support of symtab for this.
  • Unrelated: callback of slist_each changed to more traditional type. User can still pass list itself in userdata e.g. via structure.
Files:

Legend:

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

    r169 r170  
    218218    } 
    219219  delete_slist_it (it); 
    220 } 
    221  
    222 int 
    223 a60_symtab_second_resolve_symbols (a60_symtab_t * self, slist_t * ret_list, 
    224                                    a60_symtab_t * context_tab, 
    225                                    logger_t * log, cursor_t * cursor) 
    226 { 
    227   int ret = 1; 
    228   slist_it_t * it = slist_iter (self->table); 
    229   for (; slist_it_has (it); slist_it_next (it)) 
    230     { 
    231       symbol_t * sym = slist_it_get (it); 
    232       label_t const * label = symbol_label (sym); 
    233  
    234       // Skip symbols that are not implied parameters. 
    235       if (!type_is_implicit (symbol_type (sym))) 
    236         continue; 
    237  
    238       symbol_t * found = 
    239         a60_symtab_find_name_rec (context_tab, label, type_any ()); 
    240       if (found == NULL) 
    241         { 
    242           /* 
    243           int was_there = a60_symtab_add_symbol (context_tab, new_symbol_var (label), 
    244                                                  sek_ordinary); 
    245           assert (!was_there); 
    246           found = a60_symtab_find_name (self, label, type_any ()); 
    247           symbol_set_type (found, type_unknown ()); 
    248           */ 
    249  
    250           log_printfc (log, ll_error, a60_as_cursor (symbol_extra (sym)), 
    251                        "implicit parameter `%s'", 
    252                        estr_cstr (label_id (label))); 
    253           log_printfc (log, ll_error, cursor, 
    254                        "cannot be resolved at this point in file."); 
    255  
    256           ret = 0; 
    257         } 
    258       else 
    259         slist_pushback (ret_list, sym /*found*/); 
    260     } 
    261  
    262   slist_it_reset (it, ret_list); 
    263   for (; slist_it_has (it); slist_it_next (it)) 
    264     a60_symtab_erase_symbol (self, a60_as_symbol (slist_it_get (it))); 
    265  
    266   delete_slist_it (it); 
    267  
    268   return ret; 
    269220} 
    270221 
  • trunk/gcc/gcc/algol60/a60_symtab.h

    r169 r170  
    9393  ATTRIBUTE_NONNULL(1); 
    9494 
    95 /// For resolution of implicit function parameters.  This takes each 
    96 /// symbol in the symbol table, and adds into list `ret_list` a 
    97 /// symbols found by recursive lookup in `context_tab`.  The symbtab 
    98 /// `self` will be function's symbol table with implicit and explicit 
    99 /// parameters; `context_tab` will be symtab of call site. 
    100 /// 
    101 /// Only the symbols in `self` that are of type `implicit' are looked 
    102 /// up this way. 
    103 /// 
    104 /// The function returns 1 if all symbols were resolved, or 0 if there 
    105 /// were resolution errors. 
    106 int a60_symtab_second_resolve_symbols (a60_symtab_t * self, slist_t * ret_list, a60_symtab_t * context_tab, logger_t * log, cursor_t * cursor) 
    107   ATTRIBUTE_NONNULL(1) 
    108   ATTRIBUTE_NONNULL(2) 
    109   ATTRIBUTE_NONNULL(3); 
    110  
    11195typedef symbol_t * (* a60_symtab_missing_handler_t) (a60_symtab_t * self, label_t const * lbl, type_t const * atype, logger_t * log, cursor_t * cursor, void * data); 
    11296 
  • trunk/gcc/gcc/algol60/expression.c

    r169 r170  
    714714} 
    715715 
     716typedef struct { 
     717  a60_symtab_t * context_tab; 
     718  logger_t * log; 
     719  cursor_t * cursor; 
     720  slist_t * resolved; 
     721  int status; 
     722} 
     723private_resolve_context_t; 
     724 
     725static void * 
     726private_resolve_implicit_callback (symbol_t * sym, void * data) 
     727{ 
     728  private_resolve_context_t * ctx = data; 
     729  label_t const * label = symbol_label (sym); 
     730 
     731  // Skip symbols that are not implied parameters. 
     732  if (!type_is_implicit (symbol_type (sym))) 
     733    return NULL; 
     734 
     735  symbol_t * found = 
     736    a60_symtab_find_name_rec (ctx->context_tab, label, type_any ()); 
     737 
     738  if (found != NULL) 
     739    slist_pushback (ctx->resolved, sym); 
     740  else 
     741    { 
     742      log_printfc (ctx->log, ll_error, a60_as_cursor (symbol_extra (sym)), 
     743                   "implicit parameter `%s'", 
     744                   estr_cstr (label_id (label))); 
     745      log_printfc (ctx->log, ll_error, ctx->cursor, 
     746                   "cannot be resolved at this point in file."); 
     747 
     748      ctx->status = 0; 
     749    } 
     750 
     751  return NULL; 
     752} 
     753 
    716754static void 
    717755private_resolve_symbols_call (expression_t * self, 
     
    771809      container_t * f_container = a60_as_container (f_stmt); 
    772810      a60_symtab_t * f_implicit = container_symtab (f_container); 
    773       slist_t * resolved = new_slist (); 
    774811      int e_messages = log_count_messages (log, ll_error); 
    775812      int w_messages = log_count_messages (log, ll_warning); 
    776       if (a60_symtab_second_resolve_symbols (f_implicit, resolved, symtab, 
    777                                              log, expr_cursor (self))) 
     813 
     814      private_resolve_context_t ctx 
     815        = {symtab, log, expr_cursor (self), new_slist (), 1}; 
     816      a60_symtab_each 
     817        (f_implicit, a60_symbol_callback (private_resolve_implicit_callback), &ctx); 
     818      slist_it_t * it = slist_iter (ctx.resolved); 
     819      for (; slist_it_has (it); slist_it_next (it)) 
     820        a60_symtab_erase_symbol (f_implicit, a60_as_symbol (slist_it_get (it))); 
     821      delete_slist_it (it); 
     822      delete_slist (ctx.resolved); 
     823 
     824      if (ctx.status) 
    778825        { 
    779826          assert (container_parent (f_container) == NULL); 
     
    789836            log_printfc (log, level, self->cursor, "at this point in file."); 
    790837        } 
    791       delete_slist (resolved); 
    792838    } 
    793839} 
  • trunk/gcc/gcc/algol60/slist.c

    r161 r170  
    402402slist_each ( 
    403403  slist_t * list, 
    404   void (*fn)(slist_t *, void *, void *), 
     404  void (*fn)(void *, void *), 
    405405  void * userdata) 
    406406{ 
     
    412412    { 
    413413      void * obj = node->object; 
    414       (*fn) (list, obj, userdata); 
     414      (*fn) (obj, userdata); 
    415415    } 
    416416} 
     
    565565 
    566566void 
    567 incctr (slist_t * list, void * obj, void * pctr
    568 { 
    569   (*(int*)pctr)++; 
     567incctr (void * obj, void * userdata
     568{ 
     569  (*(int*)userdata)++; 
    570570} 
    571571 
    572572int 
    573 odd (slist_t * list, void * obj, void * userdata) 
     573odd (void * obj, void * userdata) 
    574574{ 
    575575  return (int)obj % 2; 
  • trunk/gcc/gcc/algol60/slist.h

    r160 r170  
    113113/// Apply the function `fn' to each element of the list `list'.  The 
    114114/// argument `userdata' will be passed over to fn verbatim.  The 
    115 /// arguments of `fn' are, respectively, the list that is iterated 
    116 /// over, the object that is currently under the cursor, and the 
    117 /// userdata passed to slist_map. 
     115/// arguments of `fn' are, respectively, the object that is currently 
     116/// under the cursor, and the userdata passed to slist_map. 
    118117void slist_each ( 
    119118  slist_t * list, 
    120   void (*fn)(slist_t * /*list*/, void * /*object*/, void * /*userdata*/), 
     119  void (*fn)(void * /*object*/, void * /*userdata*/), 
    121120  void * userdata) 
    122121  ATTRIBUTE_NONNULL(1)