Changeset 310


Ignore:
Timestamp:
Jun 10, 2003, 7:47:31 PM (22 years ago)
Author:
bird
Message:

#456: C++ methods, can finally see the arguments.

File:
1 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r309 r310  
    126126  const char *name;             /* The field name */
    127127  const char *sname;            /* Static name */
     128  const char *mnglname;         /* Mangled name for methods. (#456) */
    128129  int flags;                    /* Member flags (visibility) */
    129130};
     
    184185          struct type *ret;     /* Return type */
    185186          struct type *args;    /* Argument types */
     187          struct type *domain;  /* Domain type (C++ member) (#456) */
    186188          int arg_count;        /* Number of arguments */
    187189        } func;
     
    220222          int flags;            /* Member flags (visibility etc.) */
    221223          const char *name;     /* Name of the member function */
     224          const char *mnglname; /* Mangled Name of the member function. (#456) */
    222225        } memfunc;
    223226      struct
     
    664667              && p->d.memfunc.offset == src->d.memfunc.offset
    665668              && p->d.memfunc.flags == src->d.memfunc.flags
    666               && p->d.memfunc.name == src->d.memfunc.name)
     669              && p->d.memfunc.name == src->d.memfunc.name
     670              && p->d.memfunc.mnglname == src->d.memfunc.mnglname)
    667671            return p;
    668672          break;
     
    14881492
    14891493      ++parse_ptr;
     1494      args_grow.count = 0;  /* ASSUMES we can safely use args_grow/args_list. */
     1495      t2 = NULL;            /* t2=Domain type; t1=Return type; */
    14901496      if (*parse_ptr == '#')
    14911497        {
     
    15011507            goto syntax;
    15021508          t1 = parse_type (NULL); /* Return type */
     1509          /* Arguments */
    15031510          while (*parse_ptr != ';')
    15041511            {
    15051512              if (!parse_char (','))
    15061513                goto syntax;
    1507               t2 = parse_type (NULL); /* Argument type */
     1514              grow_by (&args_grow, 1);
     1515              args_list[args_grow.count++] = parse_type (NULL); /* Argument type */
    15081516            }
    15091517          ++parse_ptr;
    15101518        }
    15111519
     1520      t3 = NULL;
     1521      #if 0
     1522      if (args_grow.count)
     1523        {
     1524          t.tag = ty_args;
     1525          t.index = -1;
     1526          t.d.args.count = args_grow.count;
     1527          t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
     1528          memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
     1529          t3 = type_add (&t);
     1530          free (t.d.args.list);
     1531        }
     1532      #endif
     1533
    15121534      /* Make a function type from the return type t1 */
    1513 
    15141535      t.tag = ty_func;
    15151536      t.d.func.ret = t1;
    1516       t.d.func.args = NULL;
    1517       t.d.func.arg_count = 0;
     1537      t.d.func.domain = t2;
     1538      t.d.func.args = t3;
     1539      t.d.func.arg_count = args_grow.count;
     1540      args_grow.count = 0;
     1541      t1 = type_add(&t);
     1542
    15181543      break;
    15191544
     
    17041729          tf->flags = VIS_PUBLIC;
    17051730          tf->name = strpool_addn (str_pool, parse_ptr, n);
     1731          tf->mnglname = NULL;
    17061732          parse_ptr = p1 + 1;
    17071733          if (*parse_ptr == ':')
     
    17111737              do
    17121738                {
     1739                  const char * pszMangled;
     1740
    17131741                  t1 = parse_type (NULL);
    17141742                  offset = 0;
     1743                  if (t1 == NULL || t1->tag != ty_func)
     1744                    {
     1745                      no_warning ("Invalid member function type");
     1746                      goto syntax;
     1747                    }
    17151748
    17161749                  if (*parse_ptr != ':')
     
    17201753                    }
    17211754                  ++parse_ptr;
     1755                  pszMangled = parse_ptr;
    17221756                  if (!parse_mangled_args ())
    17231757                    goto syntax;
     1758                  tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES not extra spaces! */
    17241759                  tf->flags = parse_visibility () | MEMBER_FUNCTION;
    17251760                  switch (*parse_ptr)
     
    17761811                        ++parse_ptr;
    17771812                    }
     1813                  /* Contstructor / Destructor hack -
     1814                   * TODO: verify that this doesn't really work with overloaded constructors and fix it.
     1815                   */
     1816                  if (!(tf->flags & MEMBER_STATIC))
     1817                    {
     1818                      if (!strcmp(tf->name, "__comp_ctor") || !strcmp(tf->name, "__base_ctor"))
     1819                          tf->flags |= MEMBER_CTOR;
     1820                      else if (!strcmp(tf->name, "__comp_dtor") || !strcmp(tf->name, "__base_dtor"))
     1821                          tf->flags |= MEMBER_DTOR;
     1822                    }
    17781823                  tf->type = t1;
    17791824                  tf->offset = offset;
     
    18741919                  t.d.memfunc.type = t2;
    18751920                  t.d.memfunc.name = tmp_fields[i].name;
     1921                  t.d.memfunc.mnglname = tmp_fields[i].mnglname;
    18761922                  t.d.memfunc.flags = tmp_fields[i].flags;
    18771923                  t.d.memfunc.offset = tmp_fields[i].offset;
     
    26942740
    26952741
    2696 /**
    2697  * Checks if the given name is likely to be a C++ method.
    2698  *
    2699  * @returns 1 if C++ method.
    2700  * @returns 0 if not method.
    2701  * @param   pszName     Pointer to the name.
    2702  * @remark  Can also, if need, look around for symbols, types and stuff, but
    2703  *          will no alter any parser state.
    2704  */
    2705 static int isCxxMethod(const char* pszName)
    2706 {
    2707     /* not perfect, but probably close enought */
    2708     return cplusplus_flag
    2709         && pszName[0] == '_'
    2710         && pszName[1] == 'Z'
    2711         && pszName[2] == 'N';
    2712 }
    2713 
    2714 
    27152742/* Define a function.  SYMBOL points to the sym_ptr entry.  The
    27162743   function arguments are taken from the args_list array.  Several
     
    27382765  proc_start_addr = symbol->n_value;
    27392766
    2740   if (args_grow.count == 0)
    2741     t1 = NULL;
    2742   else
    2743     {
    2744       t.tag = ty_args;
    2745       t.index = -1;
    2746       t.d.args.count = args_grow.count;
    2747       t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
    2748       memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
    2749       t1 = type_add (&t);
    2750       free (t.d.args.list);
    2751     }
    2752   last_fun_type.d.func.args = t1;
    2753   last_fun_type.d.func.arg_count = args_grow.count;
    2754   t2 = type_add (&last_fun_type);
    2755   make_type (t2, &ti);
    2756   if (isCxxMethod(name))
    2757     {
    2758       /* kso #456 2003-06-05: TODO - check for methods somehow */
    2759       sst_start (cplusplus_flag ? SST_CPPproc : SST_proc);
     2767  /* now let's see if there is a memfunc for this name. */
     2768  for (t1 = type_head; t1; t1 = t1->next)
     2769    if (    t1->tag == ty_memfunc
     2770        &&  t.d.memfunc.mnglname
     2771        &&  !strcmp (t1->d.memfunc.mnglname, name))
     2772      break;
     2773
     2774  if (t1)
     2775    { /* C++ member function */
     2776      sst_start (SST_memfunc);
    27602777      r.r_address = sst.size;
    27612778      buffer_dword (&sst, symbol->n_value); /* Segment offset */
    2762       buffer_word (&sst, ti);       /* Type index */
     2779      buffer_word (&sst, t1->index);        /* Type index */
    27632780      proc_patch_base = sst.size;
    27642781      buffer_dword (&sst, 0);       /* Length of proc */
    27652782      buffer_word (&sst, 0);        /* Length of prologue */
    27662783      buffer_dword (&sst, 0);       /* Length of prologue and body */
    2767       buffer_word (&sst, 0);        /* Class type (for member functions) */
     2784      t2 = t1->d.memfunc.type;
     2785      ti = 0;
     2786      if (t2 && t2->tag == ty_func && t2->d.func.domain)
     2787          ti = t2->d.func.domain->index;
     2788      else
     2789          warning (" Can't figure out which class method '%s' is a member of!", name);
     2790      buffer_word (&sst, ti);        /* Class type (for member functions) */
    27682791      buffer_byte (&sst, 8);        /* 32-bit near */
    2769       if (cplusplus_flag)
    2770         buffer_enc (&sst, name);    /* Proc name */
     2792      buffer_enc (&sst, name);      /* Proc name */
     2793      sst_end ();
     2794    }
     2795  else
     2796    {
     2797      if (args_grow.count == 0)
     2798        t1 = NULL;
    27712799      else
    2772         buffer_nstr (&sst, name);   /* Proc name */
    2773       sst_end ();
    2774     }
    2775   else
    2776     {
     2800        {
     2801          t.tag = ty_args;
     2802          t.index = -1;
     2803          t.d.args.count = args_grow.count;
     2804          t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
     2805          memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
     2806          t1 = type_add (&t);
     2807          free (t.d.args.list);
     2808        }
     2809      last_fun_type.d.func.args = t1;
     2810      last_fun_type.d.func.arg_count = args_grow.count;
     2811      t2 = type_add (&last_fun_type);
     2812      make_type (t2, &ti);
     2813
    27772814      sst_start (cplusplus_flag ? SST_CPPproc : SST_proc);
    27782815      r.r_address = sst.size;
     
    30623099          else
    30633100            {/* kso #456 2003-06-05: We need a begin to catch the parameters. */
    3064               //block_begin (proc_start_addr);
     3101              struct relocation_info r = {0};
    30653102              sst_start (SST_begin);
    3066               buffer_dword (&sst, proc_start_addr); /* Segment offset */
    3067               buffer_dword (&sst, 10); /* Length */
     3103              r.r_address = sst.size;
     3104              buffer_dword (&sst, proc_start_addr);         /* Segment offset */
     3105              buffer_dword (&sst, text_size - proc_start_addr); /* Length */
    30683106              sst_end ();
     3107              r.r_length = 2;
     3108              r.r_symbolnum = N_TEXT;
     3109              buffer_mem (&sst_reloc, &r, sizeof (r));
     3110              prologue_length = 0;
    30693111            }
    30703112
     
    31403182  buffer_byte (&sst, lang);
    31413183  buffer_nstr (&sst, "    ");       /* Compiler options */
    3142   buffer_nstr (&sst, "");           /* Compiler date */
     3184  buffer_nstr (&sst, __DATE__);     /* Compiler date */
    31433185  buffer_mem (&sst, &ts, sizeof (ts));
    31443186  sst_end ();
Note: See TracChangeset for help on using the changeset viewer.