Changeset 746


Ignore:
Timestamp:
Sep 29, 2003, 4:00:10 PM (22 years ago)
Author:
bird
Message:

#456: Fixing problems with cyclic make_type(). Fake forward refs to enums. Corrected class search in define_fun. More info on warnings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/emxomf/stabshll.c

    • Property cvs2svn:cvs-rev changed from 1.22 to 1.23
    r745 r746  
    282282static const char *parse_ptr;
    283283
    284 /* Start of the stabs string we're parsing. Usful when printing
     284/* Start of the stabs string we're parsing. Useful when printing
    285285   messages. */
    286286static const char *parse_start;
     287
     288/* Current stabs index. Useful when printing messages. */
     289static int        *parse_pindex;
    287290
    288291/* The next HLL type index.  When creating a complex type, this index
     
    400403  fputc ('\n', stderr);
    401404
     405
    402406  if (parse_ptr && parse_start && parse_ptr >= parse_start)
    403     fprintf (stderr, "emxomf info: Currently parsing '%c' at position %ld in\n%s\n",
    404              *parse_ptr, parse_ptr - parse_start, parse_start);
     407    {
     408      if (parse_pindex && *parse_pindex >= 0 && *parse_pindex < sym_count)
     409        fprintf (stderr, "emxomf info: parsing sym no.%d type=%d at char '%c' in position %ld:\n%s\n",
     410                 *parse_pindex, sym_ptr[*parse_pindex].n_type,
     411                 *parse_ptr, parse_ptr - parse_start, parse_start);
     412      else
     413        fprintf (stderr, "emxomf info: parsing '%c' at position %ld:\n%s\n",
     414                 *parse_ptr, parse_ptr - parse_start, parse_start);
     415    }
    405416}
    406417
     
    15631574{
    15641575  const char *saved_ptr, *p1;
     1576  char ch;
    15651577  struct type t, *result, *t1, *t2, *t3, **tlist;
    15661578  int i, n, class_flag, is_void;
     
    19021914
    19031915      ++parse_ptr;
    1904       switch (*parse_ptr)
     1916      ch = *parse_ptr++;
     1917      p1 = nextcolon (parse_ptr);
     1918      if (p1 == NULL)
     1919        {
     1920          warning ("Invalid forward reference: missing colon");
     1921          goto syntax;
     1922        }
     1923
     1924      switch (ch)
    19051925        {
    19061926        case 's':
    19071927        case 'u':
    1908           break;
    1909         case 'e':
    1910           warning ("Cannot convert incomplete enum type");
    1911           goto syntax;
    1912         default:
    1913           warning ("Unknown forward reference: %c", *parse_ptr);
    1914           goto syntax;
    1915         }
    1916       ++parse_ptr;
    1917       p1 = nextcolon (parse_ptr);
    1918       if (p1 == NULL)
    1919         {
    1920           warning ("Invalid forward reference: missing colon");
    1921           goto syntax;
    1922         }
    1923       t.tag = ty_struc;
    1924       t.d.struc.types = NULL;
    1925       t.d.struc.fields = NULL;
    1926       t.d.struc.size = 0;
    1927       t.d.struc.count = 0;
    1928       t.d.struc.name = strpool_addn (str_pool, parse_ptr, p1 - parse_ptr);
    1929       t.d.struc.flags = STRUC_FORWARD;
    1930 
    1931       /* Avoid adding an incomplete type if the complete one is
    1932          already defined.  We're ignoring scoping (TODO). */
    1933 
    1934       for (t3 = type_head; t3 != NULL; t3 = t3->next)
    1935         if ((t3->tag == ty_struc && t3->d.struc.name == t.d.struc.name
    1936              && !(t3->d.struc.flags & STRUC_FORWARD))
    1937             || (t3->tag == ty_class && t3->d.class.name == t.d.struc.name))
    19381928          {
    1939             result = t3;
     1929            t.tag = ty_struc;
     1930            t.d.struc.types = NULL;
     1931            t.d.struc.fields = NULL;
     1932            t.d.struc.size = 0;
     1933            t.d.struc.count = 0;
     1934            t.d.struc.name = strpool_addn (str_pool, parse_ptr, p1 - parse_ptr);
     1935            t.d.struc.flags = STRUC_FORWARD;
     1936
     1937            /* Avoid adding an incomplete type if the complete one is
     1938               already defined.  We're ignoring scoping (TODO). */
     1939
     1940            for (t3 = type_head; t3 != NULL; t3 = t3->next)
     1941              if ((t3->tag == ty_struc && t3->d.struc.name == t.d.struc.name
     1942                   && !(t3->d.struc.flags & STRUC_FORWARD))
     1943                  || (t3->tag == ty_class && t3->d.class.name == t.d.struc.name))
     1944                {
     1945                  result = t3;
     1946                  break;
     1947                }
    19401948            break;
    19411949          }
     1950
     1951        case 'e':
     1952          { /* just make it a primary. */
     1953            /** @todo make an enum perhaps? */
     1954            t.tag = ty_prim;
     1955            t.index = 0x82;             /* 32 bit signed */
     1956            break;
     1957          }
     1958
     1959        default:
     1960          warning ("Unknown forward reference: %c", ch);
     1961          parse_ptr = p1 + 1;
     1962          goto syntax;
     1963        }
    19421964      parse_ptr = p1 + 1;
    19431965      break;
    19441966
    1945     case 's':                   /* struct, class */
    1946     case 'u':                   /* union */
     1967    case 's':                           /* struct, class */
     1968    case 'u':                           /* union */
    19471969
    19481970      /* Structures, unions and classes:
     
    24882510{
    24892511  struct type *t1;
    2490   int ti_1, ti_2, i, qual;
     2512  int ti_1, ti_2, ti_3, i, qual;
    24912513  int patch1;
    24922514
    24932515#define RETURN(X) do {*hll = (X); return;} while (0)
    24942516
    2495   if (tp->index == -2)
    2496     {
    2497       warning_parse ("Cycle detected by make_type.");
    2498       RETURN (0);
    2499     }
    2500   if (tp->index != -1)
     2517  if (tp->index <= -2)
     2518    {
     2519      /* bird: A hack where we allow a 2nd recursion of rectain types.
     2520       * The normal issue is C++ class references. */
     2521      if (tp->tag != ty_alias || tp->index <= -3)
     2522        {
     2523          warning_parse ("Cycle detected by make_type.");
     2524          RETURN (0);
     2525        }
     2526    }
     2527  if (tp->index > -1)
    25012528    RETURN (tp->index);
    2502   tp->index = -2;
     2529  tp->index--;
    25032530  switch (tp->tag)
    25042531    {
     
    26372664
    26382665    case ty_member:
    2639       make_type (tp->d.member.type, &ti_1);
    26402666      qual = 0;
    26412667      if (tp->d.member.flags & MEMBER_STATIC)
     
    26432669      tt_start (0x46, qual);
    26442670      tt_byte (tp->d.member.flags & MEMBER_VIS);
    2645       tt_word (ti_1);
     2671      patch1 = tt.size;
     2672      tt_word (0);
    26462673      tt_unsigned_span (tp->d.member.offset);
    26472674      if (tp->d.member.flags & MEMBER_STATIC)
     
    26522679      tt_end ();
    26532680      *hll = tp->index = hll_type_index++;
     2681
     2682      make_type (tp->d.member.type, &ti_1);
     2683      buffer_patch_word (&tt, patch1, ti_1);
    26542684      break;
    26552685
     
    26882718
    26892719    case ty_func:
     2720      tt_start (0x54, 0x05);          /* Function */
     2721      tt_word (tp->d.func.arg_count); /* Number of parameters */
     2722      tt_word (tp->d.func.arg_count); /* Max. Number of parameters */
     2723      patch1 = tt.size;
     2724      tt_index (0);                   /* Return value */
     2725      tt_index (0);                   /* Argument list */
     2726      tt_end ();
     2727      *hll = tp->index = hll_type_index++;
     2728
     2729      if (tp->d.func.domain)
     2730        make_type (tp->d.func.domain, &ti_3);
    26902731      make_type (tp->d.func.ret, &ti_1);
    26912732      if (tp->d.func.args == NULL)
     
    26932734      else
    26942735        make_type (tp->d.func.args, &ti_2);
    2695       tt_start (0x54, 0x05);          /* Function */
    2696       tt_word (tp->d.func.arg_count); /* Number of parameters */
    2697       tt_word (tp->d.func.arg_count); /* Max. Number of parameters */
    2698       tt_index (ti_1);                /* Return value */
    2699       tt_index (ti_2);                /* Argument list */
    2700       tt_end ();
    2701       *hll = tp->index = hll_type_index++;
     2736      buffer_patch_word (&tt, patch1+1, ti_1);
     2737      buffer_patch_word (&tt, patch1+4, ti_2);
    27022738      break;
    27032739
     
    29022938
    29032939  alloc_flag = concat_symbols (index, &str);
     2940  parse_start = str;
     2941  parse_pindex = index;
    29042942  p = nextcolon (str);
    29052943  if (p != NULL)
     
    29122950      printf ("LSYM/LCSYM/GSYM/PSYM/RSYM/STSYM/FUN %s\n", str);
    29132951#endif
    2914       parse_start = parse_ptr = p + 1;
     2952      parse_ptr = p + 1;
    29152953      switch (*parse_ptr)
    29162954        {
     
    31223160  struct type t, *t1, *t2, *t3;
    31233161  struct relocation_info r;
    3124   const char *str, *p;
     3162  const char *str, *p, *p2;
    31253163  const char *name;
    31263164  int n,                                /* size of name. */
     
    31453183  if (t1)
    31463184    { /* C++ member function */
    3147       ti = t1->index;
    3148       if (ti == -1)
    3149         make_type (t1, &ti);
    3150 
    31513185      t2 = t1->d.memfunc.type;
    31523186      if (t2 && t2->tag == ty_func && t2->d.func.domain)
    3153           ticlass = t2->d.func.domain->index;
     3187        make_type (t2->d.func.domain, &ticlass);
    31543188      else
    3155         { /* the hard way - search for the freaking string in suitable .stabs. */
     3189        { /* the hard way - search for the freaking string in suitable .stabs.
     3190           * I think this is rather slow when done for many members.. :/ */
    31563191          int i;
    31573192          for (i = 0, t3 = NULL, ticlass = -1; !t3 && i < sym_count; ++i)
     
    31613196                {
    31623197                  str = str_ptr + sym_ptr[i].n_un.n_strx;
    3163                   if ((p = strstr (str, name)) != NULL
    3164                    /** @todo parse the string to get the name right. */
    3165                    && p[-1] == ':' && p[n] == ';')
     3198                  p = nextcolon (str);
     3199                  if (p && p[1] == 'T' && p[2] == 't')
    31663200                    {
    3167                       p = nextcolon (str);
    3168                       if (p && p[1] == 'T' && p[2] == 't')
     3201                      /* Now, there can be several name which NAME is a
     3202                       * substring in.
     3203                       */
     3204                      /** @todo: the string parsing still is a bit spooky. */
     3205                      for (p2 = p; (p2 = strstr (p2, name)) != NULL; p2 += n)
     3206                        if (p2[-1] == ':' && p2[n] == ';')
    31693207                        {
    3170                           int stab = atoi (&p[3]);
    3171                           t3 = stype_find (stab);
     3208                            int stab = atoi (&p[3]);
     3209                            t3 = stype_find (stab);
     3210                            break;
    31723211                        }
    31733212                    }
     
    31843223        }
    31853224
     3225      make_type (t1, &ti);
    31863226      sst_start (SST_memfunc);
    31873227      r.r_address = sst.size;
     
    32803320  symbol = &sym_ptr[*index];
    32813321  alloc_flag = concat_symbols (index, &str);
     3322  parse_start = str;
     3323  parse_pindex = index;
    32823324  p = nextcolon (str);
    32833325  if (p != NULL)
     
    32913333#endif
    32923334
    3293       parse_start = parse_ptr = p + 1;
     3335      parse_ptr = p + 1;
    32943336      switch (*parse_ptr)
    32953337        {
Note: See TracChangeset for help on using the changeset viewer.