* lib/ld-lib.exp (run_dump_test): Add -L$srcdir/$subdir.
[external/binutils.git] / ld / deffilep.y
index aacde6b..51d17f8 100644 (file)
@@ -1,6 +1,7 @@
 %{ /* deffilep.y - parser for .def files */
 
-/*   Copyright (C) 1995, 1997, 1998, 1999 Free Software Foundation, Inc.
+/*   Copyright 1995, 1997, 1998, 1999, 2000, 2001
+     Free Software Foundation, Inc.
 
 This file is part of GNU Binutils.
 
@@ -19,8 +20,8 @@ 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"
@@ -77,14 +78,13 @@ 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_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,7 +93,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 int def_debug;
+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;
@@ -107,9 +109,10 @@ static const char *lex_parse_string_end = 0;
   int number;
 };
 
-%token NAME, LIBRARY, DESCRIPTION, STACKSIZE, HEAPSIZE, CODE, DATA
-%token SECTIONS, EXPORTS, IMPORTS, VERSIONK, BASE, CONSTANT, PRIVATE
-%token READ WRITE EXECUTE SHARED NONAME DIRECTIVE
+%token NAME, LIBRARY, DESCRIPTION, STACKSIZE, HEAPSIZE, CODE, DATAU, DATAL
+%token SECTIONS, EXPORTS, IMPORTS, VERSIONK, BASE, CONSTANTU, CONSTANTL
+%token PRIVATEU, PRIVATEL
+%token READ WRITE EXECUTE SHARED NONAMEU NONAMEL DIRECTIVE
 %token <id> ID
 %token <number> NUMBER
 %type  <number> opt_base opt_ordinal
@@ -129,7 +132,7 @@ command:
        |       STACKSIZE NUMBER opt_number { def_stacksize ($2, $3);}
        |       HEAPSIZE NUMBER opt_number { def_heapsize ($2, $3);}
        |       CODE attr_list { def_section ("CODE", $2);}
-       |       DATA attr_list  { def_section ("DATA", $2);}
+       |       DATAU attr_list  { def_section ("DATA", $2);}
        |       SECTIONS seclist
        |       EXPORTS explist 
        |       IMPORTS implist
@@ -146,18 +149,28 @@ explist:
        ;
 
 expline:
-               ID opt_equal_name opt_ordinal exp_opt_list
-                       { def_exports ($1, $2, $3, $4); }
+               /* 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
+                       { def_exports ($1, $2, $3, $5); }
        ;
 exp_opt_list:
-               exp_opt exp_opt_list { $$ = $1 | $2; }
+               /* The opt_comma is necessary to support both the usual
+                  DEF file syntax as well as .drectve syntax which
+                  allows for comma separated opt list.  */
+               exp_opt opt_comma exp_opt_list { $$ = $1 | $3; }
        |       { $$ = 0; }
        ;
 exp_opt:
-               NONAME          { $$ = 1; }
-       |       CONSTANT        { $$ = 2; }
-       |       DATA            { $$ = 4; }
-       |       PRIVATE         { $$ = 8; }
+               NONAMEU         { $$ = 1; }
+       |       NONAMEL         { $$ = 1; }
+       |       CONSTANTU       { $$ = 2; }
+       |       CONSTANTL       { $$ = 2; }
+       |       DATAU           { $$ = 4; }
+       |       DATAL           { $$ = 4; }
+       |       PRIVATEU        { $$ = 8; }
+       |       PRIVATEL        { $$ = 8; }
        ;
 implist:       
                implist impline
@@ -204,7 +217,13 @@ attr:
        ;
 
 opt_name: ID           { $$ = $1; }
-       |               { $$ = 0; }
+       | ID '.' ID     
+         { 
+           char * name = xmalloc (strlen ($1) + 1 + strlen ($3) + 1);
+           sprintf (name, "%s.%s", $1, $3);
+           $$ = name;
+         }
+       |               { $$ = ""; }
        ;
 
 opt_ordinal: 
@@ -477,7 +496,7 @@ def_file_add_export (def, external_name, internal_name, ordinal)
 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)
@@ -514,7 +533,7 @@ def_file_add_import (def, name, module, ordinal, internal_name)
   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);
@@ -553,10 +572,10 @@ 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 < pend && !(ISSPACE (tend[-1]) && *tend == '-');
           tend++);
 
       for (i = 0; diropts[i].param; i++)
@@ -828,8 +847,10 @@ tokens[] =
 {
   { "BASE", BASE },
   { "CODE", CODE },
-  { "CONSTANT", CONSTANT },
-  { "DATA", DATA },
+  { "CONSTANT", CONSTANTU },
+  { "constant", CONSTANTL },
+  { "DATA", DATAU },
+  { "data", DATAL },
   { "DESCRIPTION", DESCRIPTION },
   { "DIRECTIVE", DIRECTIVE },
   { "EXECUTE", EXECUTE },
@@ -838,8 +859,10 @@ tokens[] =
   { "IMPORTS", IMPORTS },
   { "LIBRARY", LIBRARY },
   { "NAME", NAME },
-  { "NONAME", NONAME },
-  { "PRIVATE", PRIVATE },
+  { "NONAME", NONAMEU },
+  { "noname", NONAMEL },
+  { "PRIVATE", PRIVATEU },
+  { "private", PRIVATEL },
   { "READ", READ },
   { "SECTIONS", SECTIONS },
   { "SEGMENTS", SECTIONS },
@@ -926,10 +949,10 @@ def_lex ()
   /* 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 ();
@@ -943,10 +966,10 @@ def_lex ()
       return NUMBER;
     }
 
-  if (isalpha (c) || strchr ("$:-_?", c))
+  if (ISALPHA (c) || strchr ("$:-_?", c))
     {
       bufptr = 0;
-      while (c != EOF && (isalnum (c) || strchr ("$:-_?/@", c)))
+      while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@", c)))
        {
          put_buf (c);
          c = def_getc ();