* alpha-tdep.c (alpha_register_type): Change from _virtual_type.
[binutils-gdb.git] / ld / deffilep.y
index 760167b4ce549e8a40a66020717f46bc5e63b090..45b1bda6f43a936f4cf6176eeeaae4d94e76ec52 100644 (file)
@@ -1,26 +1,27 @@
 %{ /* deffilep.y - parser for .def files */
 
-/*   Copyright (C) 1995, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/*   Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+     Free Software Foundation, Inc.
 
-This file is part of GNU Binutils.
+     This file is part of GNU Binutils.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 2 of the License, or
+     (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+     GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+     You should have received a copy of the GNU General Public License
+     along with this program; if not, write to the Free Software
+     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include <stdio.h>
-#include <ctype.h>
 #include "libiberty.h"
+#include "safe-ctype.h"
 #include "bfd.h"
 #include "sysdep.h"
 #include "ld.h"
@@ -36,7 +37,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    yacc generated parsers in ld.  Note that these are only the variables
    produced by yacc.  If other parser generators (bison, byacc, etc) produce
    additional global names that conflict at link time, then those parser
-   generators need to be fixed instead of adding those names to this list. */
+   generators need to be fixed instead of adding those names to this list.  */
 
 #define        yymaxdepth def_maxdepth
 #define        yyparse def_parse
@@ -65,8 +66,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define        yy_yyv  def_yyv
 #define        yyval   def_val
 #define        yylloc  def_lloc
-#define yyreds def_reds                /* With YYDEBUG defined */
-#define yytoks def_toks                /* With YYDEBUG defined */
+#define yyreds def_reds                /* With YYDEBUG defined */
+#define yytoks def_toks                /* With YYDEBUG defined */
 #define yylhs  def_yylhs
 #define yylen  def_yylen
 #define yydefred def_yydefred
@@ -77,14 +78,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define yytable         def_yytable
 #define yycheck         def_yycheck
 
-static int def_lex ();
-
 static void def_description PARAMS ((const char *));
 static void def_exports PARAMS ((const char *, const char *, int, int));
 static void def_heapsize PARAMS ((int, int));
-static void def_import
-  PARAMS ((const char *, const char *, const char *, const char *, int));
+static void def_import PARAMS ((const char *, const char *, const char *, const char *, int));
 static void def_library PARAMS ((const char *, int));
+static def_file_module *def_stash_module PARAMS ((def_file *, const char *));
 static void def_name PARAMS ((const char *, int));
 static void def_section PARAMS ((const char *, int));
 static void def_section_alt PARAMS ((const char *, const char *));
@@ -93,6 +92,9 @@ static void def_version PARAMS ((int, int));
 static void def_directive PARAMS ((char *));
 static int def_parse PARAMS ((void));
 static int def_error PARAMS ((const char *));
+static void put_buf PARAMS ((char));
+static int def_getc PARAMS ((void));
+static int def_ungetc PARAMS ((int));
 static int def_lex PARAMS ((void));
 
 static int lex_forced_token = 0;
@@ -114,7 +116,7 @@ static const char *lex_parse_string_end = 0;
 %token <number> NUMBER
 %type  <number> opt_base opt_ordinal
 %type  <number> attr attr_list opt_number exp_opt_list exp_opt
-%type  <id> opt_name opt_equal_name 
+%type  <id> opt_name opt_equal_name dot_name 
 
 %%
 
@@ -149,7 +151,7 @@ expline:
                /* The opt_comma is necessary to support both the usual
                  DEF file syntax as well as .drectve syntax which
                  mandates <expsym>,<expoptlist>.  */
-               ID opt_equal_name opt_ordinal opt_comma exp_opt_list
+               dot_name opt_equal_name opt_ordinal opt_comma exp_opt_list
                        { def_exports ($1, $2, $3, $5); }
        ;
 exp_opt_list:
@@ -229,14 +231,22 @@ opt_ordinal:
        ;
 
 opt_equal_name:
-          '=' ID       { $$ = $2; }
+          '=' dot_name { $$ = $2; }
         |              { $$ =  0; }                     
        ;
 
 opt_base: BASE '=' NUMBER      { $$ = $3;}
-       |       { $$ = 0;}
+       |       { $$ = -1;}
        ;
 
+dot_name: ID           { $$ = $1; }
+       | dot_name '.' ID       
+         { 
+           char * name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
+           sprintf (name, "%s.%s", $1, $3);
+           $$ = name;
+         }
+       ;
        
 
 %%
@@ -323,6 +333,7 @@ def_file_free (def)
      def_file *def;
 {
   int i;
+
   if (!def)
     return;
   if (def->name)
@@ -385,6 +396,7 @@ def_file_print (file, def)
      def_file *def;
 {
   int i;
+
   fprintf (file, ">>>> def_file at 0x%08x\n", def);
   if (def->name)
     fprintf (file, "  name: %s\n", def->name ? def->name : "(unspecified)");
@@ -406,6 +418,7 @@ def_file_print (file, def)
   if (def->num_section_defs > 0)
     {
       fprintf (file, "  section defs:\n");
+
       for (i = 0; i < def->num_section_defs; i++)
        {
          fprintf (file, "    name: `%s', class: `%s', flags:",
@@ -425,6 +438,7 @@ def_file_print (file, def)
   if (def->num_exports > 0)
     {
       fprintf (file, "  exports:\n");
+
       for (i = 0; i < def->num_exports; i++)
        {
          fprintf (file, "    name: `%s', int: `%s', ordinal: %d, flags:",
@@ -445,6 +459,7 @@ def_file_print (file, def)
   if (def->num_imports > 0)
     {
       fprintf (file, "  imports:\n");
+
       for (i = 0; i < def->num_imports; i++)
        {
          fprintf (file, "    int: %s, from: `%s', name: `%s', ordinal: %d\n",
@@ -454,8 +469,10 @@ def_file_print (file, def)
                   def->imports[i].ordinal);
        }
     }
+
   if (def->version_major != -1)
     fprintf (file, "  version: %d.%d\n", def->version_major, def->version_minor);
+
   fprintf (file, "<<<< def_file at 0x%08x\n", def);
 }
 #endif
@@ -469,13 +486,16 @@ def_file_add_export (def, external_name, internal_name, ordinal)
 {
   def_file_export *e;
   int max_exports = ROUND_UP(def->num_exports, 32);
+
   if (def->num_exports >= max_exports)
     {
-      max_exports = ROUND_UP(def->num_exports+1, 32);
+      max_exports = ROUND_UP(def->num_exports + 1, 32);
       if (def->exports)
-       def->exports = (def_file_export *) xrealloc (def->exports, max_exports * sizeof (def_file_export));
+       def->exports = (def_file_export *)
+         xrealloc (def->exports, max_exports * sizeof (def_file_export));
       else
-       def->exports = (def_file_export *) xmalloc (max_exports * sizeof (def_file_export));
+       def->exports = (def_file_export *)
+         xmalloc (max_exports * sizeof (def_file_export));
     }
   e = def->exports + def->num_exports;
   memset (e, 0, sizeof (def_file_export));
@@ -490,14 +510,28 @@ def_file_add_export (def, external_name, internal_name, ordinal)
   return e;
 }
 
+def_file_module *
+def_get_module (def, name)
+     def_file *def;
+     const char *name;
+{
+  def_file_module *s;
+
+  for (s = def->modules; s; s = s->next)
+    if (strcmp (s->name, name) == 0)
+      return s;
+
+  return (def_file_module *) 0;
+}
+
 static def_file_module *
 def_stash_module (def, name)
      def_file *def;
-     char *name;
+     const char *name;
 {
   def_file_module *s;
-  for (s=def->modules; s; s=s->next)
-    if (strcmp (s->name, name) == 0)
+
+  if ((s = def_get_module (def, name)) != (def_file_module *) 0)
       return s;
   s = (def_file_module *) xmalloc (sizeof (def_file_module) + strlen (name));
   s->next = def->modules;
@@ -517,26 +551,31 @@ def_file_add_import (def, name, module, ordinal, internal_name)
 {
   def_file_import *i;
   int max_imports = ROUND_UP(def->num_imports, 16);
+
   if (def->num_imports >= max_imports)
     {
       max_imports = ROUND_UP(def->num_imports+1, 16);
+
       if (def->imports)
-       def->imports = (def_file_import *) xrealloc (def->imports, max_imports * sizeof (def_file_import));
+       def->imports = (def_file_import *)
+         xrealloc (def->imports, max_imports * sizeof (def_file_import));
       else
-       def->imports = (def_file_import *) xmalloc (max_imports * sizeof (def_file_import));
+       def->imports = (def_file_import *)
+         xmalloc (max_imports * sizeof (def_file_import));
     }
   i = def->imports + def->num_imports;
   memset (i, 0, sizeof (def_file_import));
   if (name)
     i->name = xstrdup (name);
   if (module)
-    i->module = def_stash_module(def, module);
+    i->module = def_stash_module (def, module);
   i->ordinal = ordinal;
   if (internal_name)
     i->internal_name = xstrdup (internal_name);
   else
     i->internal_name = i->name;
   def->num_imports++;
+
   return i;
 }
 
@@ -569,15 +608,18 @@ def_file_add_directive (my_def, param, len)
 
   while (param < pend)
     {
-      while (param < pend && isspace (*param))
+      while (param < pend && ISSPACE (*param))
        param++;
+
       for (tend = param + 1;
-          tend < pend && !(isspace (tend[-1]) && *tend == '-');
-          tend++);
+          tend < pend && !(ISSPACE (tend[-1]) && *tend == '-');
+          tend++)
+       ;
 
       for (i = 0; diropts[i].param; i++)
        {
          int len = strlen (diropts[i].param);
+
          if (tend - param >= len
              && strncmp (param, diropts[i].param, len) == 0
              && (param[len] == ':' || param[len] == ' '))
@@ -592,11 +634,10 @@ def_file_add_directive (my_def, param, len)
        }
 
       if (!diropts[i].param)
-       {
-         /* xgettext:c-format */
-         einfo (_("Warning: .drectve `%.*s' unrecognized\n"),
-                tend - param, param);
-       }
+       /* xgettext:c-format */
+       einfo (_("Warning: .drectve `%.*s' unrecognized\n"),
+              tend - param, param);
+
       lex_parse_string = 0;
       param = tend;
     }
@@ -604,9 +645,7 @@ def_file_add_directive (my_def, param, len)
   def = save_def;
 }
 
-/*****************************************************************************
- Parser Callbacks
- *****************************************************************************/
+/* Parser Callbacks.  */
 
 static void
 def_name (name, base)
@@ -637,6 +676,7 @@ def_description (text)
      const char *text;
 {
   int len = def->description ? strlen (def->description) : 0;
+
   len += strlen (text) + 1;
   if (def->description)
     {
@@ -675,9 +715,11 @@ def_section (name, attr)
 {
   def_file_section *s;
   int max_sections = ROUND_UP(def->num_section_defs, 4);
+
   if (def->num_section_defs >= max_sections)
     {
       max_sections = ROUND_UP(def->num_section_defs+1, 4);
+
       if (def->section_defs)
        def->section_defs = (def_file_section *) xrealloc (def->section_defs, max_sections * sizeof (def_file_import));
       else
@@ -704,6 +746,7 @@ def_section_alt (name, attr)
      const char *attr;
 {
   int aval = 0;
+
   for (; *attr; attr++)
     {
       switch (*attr)
@@ -764,13 +807,11 @@ def_import (internal_name, module, dllext, name, ordinal)
      int ordinal;
 {
   char *buf = 0;
-
-  if (dllext != NULL)
-    {
-      buf = (char *) xmalloc (strlen (module) + strlen (dllext) + 2);
-      sprintf (buf, "%s.%s", module, dllext);
-      module = buf;
-    }
+  const char *ext = dllext ? dllext : "dll";    
+   
+  buf = (char *) xmalloc (strlen (module) + strlen (ext) + 2);
+  sprintf (buf, "%s.%s", module, ext);
+  module = buf;
 
   def_file_add_import (def, name, module, ordinal, internal_name);
   if (buf)
@@ -791,6 +832,7 @@ def_directive (str)
      char *str;
 {
   struct directive *d = (struct directive *) xmalloc (sizeof (struct directive));
+
   d->next = directives;
   directives = d;
   d->name = xstrdup (str);
@@ -807,14 +849,12 @@ def_error (err)
 }
 
 
-/*****************************************************************************
- Lexical Scanner
- *****************************************************************************/
+/* Lexical Scanner.  */
 
 #undef TRACE
 #define TRACE 0
 
-/* Never freed, but always reused as needed, so no real leak */
+/* Never freed, but always reused as needed, so no real leak */
 static char *buffer = 0;
 static int buflen = 0;
 static int bufptr = 0;
@@ -825,14 +865,14 @@ put_buf (c)
 {
   if (bufptr == buflen)
     {
-      buflen += 50;            /* overly reasonable, eh? */
+      buflen += 50;            /* overly reasonable, eh?  */
       if (buffer)
        buffer = (char *) xrealloc (buffer, buflen + 1);
       else
        buffer = (char *) xmalloc (buflen + 1);
     }
   buffer[bufptr++] = c;
-  buffer[bufptr] = 0;          /* not optimal, but very convenient */
+  buffer[bufptr] = 0;          /* not optimal, but very convenient */
 }
 
 static struct
@@ -874,6 +914,7 @@ static int
 def_getc ()
 {
   int rv;
+
   if (lex_parse_string)
     {
       if (lex_parse_string >= lex_parse_string_end)
@@ -920,7 +961,7 @@ def_lex ()
 
   c = def_getc ();
 
-  /* trim leading whitespace */
+  /* Trim leading whitespace.  */
   while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
     c = def_getc ();
 
@@ -943,13 +984,14 @@ def_lex ()
        return def_lex ();
       return 0;
     }
-  /* must be something else */
+
+  /* Must be something else.  */
   saw_newline = 0;
 
-  if (isdigit (c))
+  if (ISDIGIT (c))
     {
       bufptr = 0;
-      while (c != EOF && (isxdigit (c) || (c == 'x')))
+      while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
        {
          put_buf (c);
          c = def_getc ();
@@ -963,24 +1005,45 @@ def_lex ()
       return NUMBER;
     }
 
-  if (isalpha (c) || strchr ("$:-_?", c))
+  if (ISALPHA (c) || strchr ("$:-_?@", c))
     {
       bufptr = 0;
-      while (c != EOF && (isalnum (c) || strchr ("$:-_?/@", c)))
+      q = c;
+      put_buf (c);
+      c = def_getc ();
+
+      if (q == '@')
+       {
+          if (ISBLANK (c) ) /* '@' followed by whitespace.  */
+           return (q);
+          else if (ISDIGIT (c)) /* '@' followed by digit.  */
+            {
+             def_ungetc (c);
+              return (q);
+           }
+#if TRACE
+         printf ("lex: @ returns itself\n");
+#endif
+       }
+
+      while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@", c)))
        {
          put_buf (c);
          c = def_getc ();
        }
       if (c != EOF)
        def_ungetc (c);
-      for (i = 0; tokens[i].name; i++)
-       if (strcmp (tokens[i].name, buffer) == 0)
-         {
+      if (ISALPHA (q)) /* Check for tokens.  */
+       {
+          for (i = 0; tokens[i].name; i++)
+           if (strcmp (tokens[i].name, buffer) == 0)
+             {
 #if TRACE
-           printf ("lex: `%s' is a string token\n", buffer);
+               printf ("lex: `%s' is a string token\n", buffer);
 #endif
-           return tokens[i].token;
-         }
+               return tokens[i].token;
+             }
+       }
 #if TRACE
       printf ("lex: `%s' returns ID\n", buffer);
 #endif
@@ -993,6 +1056,7 @@ def_lex ()
       q = c;
       c = def_getc ();
       bufptr = 0;
+
       while (c != EOF && c != q)
        {
          put_buf (c);
@@ -1005,7 +1069,7 @@ def_lex ()
       return ID;
     }
 
-  if (c == '=' || c == '.' || c == '@' || c == ',')
+  if (c == '=' || c == '.' || c == ',')
     {
 #if TRACE
       printf ("lex: `%c' returns itself\n", c);