daily update
[binutils-gdb.git] / ld / ldlex.l
index e8214942f70baa48aa2611a8214800bf0c31116a..c9eb1afe39548d504215718336eaeaa8c4238718 100644 (file)
@@ -1,6 +1,7 @@
 %{
 
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+/* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001, 2002  Free Software Foundation, Inc.
 
 This file is part of GLD, the Gnu Linker.
 
@@ -15,8 +16,9 @@ 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 GLD; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+along with GLD; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
 
 /*
 This was written by steve chamberlain
@@ -24,9 +26,8 @@ This was written by steve chamberlain
 */
 
 
-#include <ansidecl.h>
+#include "ansidecl.h"
 #include <stdio.h>
-#include <ctype.h>
 
 #ifdef MPW
 /* Prevent enum redefinition problems. */
@@ -35,22 +36,22 @@ This was written by steve chamberlain
 
 #include "bfd.h"
 #include "sysdep.h"
+#include "safe-ctype.h"
+#include "bfdlink.h"
 #include "ld.h"
-#include "ldgram.h"
 #include "ldmisc.h"
 #include "ldexp.h"
 #include "ldlang.h"
+#include <ldgram.h>
 #include "ldfile.h"
 #include "ldlex.h"
 #include "ldmain.h"
+#include "libiberty.h"
 
 /* The type of top-level parser input.
    yylex and yyparse (indirectly) both check this.  */
 input_type parser_input;
 
-/* Radix to use for bfd_scan_vma -- 0 (default to base 10) or 16.  */
-int hex_mode;
-
 /* Line number in the current input file.
    (FIXME Actually, it doesn't appear to get reset for each file?)  */
 unsigned int lineno = 1;
@@ -75,6 +76,7 @@ static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
 static const char *file_name_stack[MAX_INCLUDE_DEPTH];
 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
 static unsigned int include_stack_ptr = 0;
+static int vers_node_nesting = 0;
 
 static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
                                                        size_t size));
@@ -115,7 +117,7 @@ WHITE               [ \t\n\r]+
 NOCFILENAMECHAR        [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
 
 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
-V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
+V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^]([*?.$_a-zA-Z0-9\[\]\-\!\^]|::)*
 
 %s SCRIPT
 %s EXPRESSION
@@ -142,16 +144,17 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
        }
     }
 
-<BOTH,SCRIPT,EXPRESSION>"/*"   { comment(); }
+<BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*"  { comment(); }
 
 
 <DEFSYMEXP>"-"                  { RTOKEN('-');}
 <DEFSYMEXP>"+"                  { RTOKEN('+');}
-<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = buystring(yytext); return NAME; }
+<DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}*   { yylval.name = xstrdup(yytext); return NAME; }
 <DEFSYMEXP>"="                  { RTOKEN('='); }
 
 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
                                yylval.integer = bfd_scan_vma (yytext+1, 0,16);
+                               yylval.bigint.str = (char *) 0;
                                return INT;
                        }
 
@@ -177,19 +180,36 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
                                   }
                                   yylval.integer = bfd_scan_vma (yytext, 0,
                                                                  ibase);
+                                  yylval.bigint.str = (char *) 0;
                                   return INT;
                                 }
-<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>"$"?"0x"?([0-9A-Fa-f])+(M|K|m|k)? {
-                                 yylval.integer = bfd_scan_vma (yytext, 0,
-                                                                hex_mode);
-                                 if (yytext[yyleng-1]=='M'
-                                       || yytext[yyleng-1] == 'm') {
-                                     yylval.integer *= 1024*1024;
-                                   }   
-                                 if (yytext[yyleng-1]=='K' 
-                               || yytext[yyleng-1]=='k') {
+<SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
+                                 char *s = yytext;
+                                 int ibase = 0;
+
+                                 if (*s == '$')
+                                   {
+                                     ++s;
+                                     ibase = 16;
+                                   }
+                                 yylval.integer = bfd_scan_vma (s, 0, ibase);
+                                 yylval.bigint.str = (char *) 0;
+                                 if (yytext[yyleng-1] == 'M'
+                                     || yytext[yyleng-1] == 'm')
+                                   {
+                                     yylval.integer *= 1024 * 1024;
+                                   }
+                                 else if (yytext[yyleng-1] == 'K' 
+                                     || yytext[yyleng-1]=='k')
+                                   {
                                      yylval.integer *= 1024;
-                                   }           
+                                   }
+                                 else if (yytext[0] == '0'
+                                          && (yytext[1] == 'x'
+                                              || yytext[1] == 'X'))
+                                   {
+                                     yylval.bigint.str = xstrdup (yytext + 2);
+                                   }
                                  return INT;
                                }
 <BOTH,SCRIPT,EXPRESSION,MRI>"]"                { RTOKEN(']');}
@@ -232,16 +252,20 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 <BOTH,SCRIPT,EXPRESSION,MRI>";"                { RTOKEN(';');}
 <BOTH,SCRIPT>"MEMORY"          { RTOKEN(MEMORY);}
 <BOTH,SCRIPT>"ORIGIN"          { RTOKEN(ORIGIN);}
-<BOTH,SCRIPT>"VERSION"         { RTOKEN(VERSION);}
+<BOTH,SCRIPT>"VERSION"         { RTOKEN(VERSIONK);}
 <EXPRESSION,BOTH,SCRIPT>"BLOCK"                { RTOKEN(BLOCK);}
 <EXPRESSION,BOTH,SCRIPT>"BIND"         { RTOKEN(BIND);}
 <BOTH,SCRIPT>"LENGTH"          { RTOKEN(LENGTH);}
 <EXPRESSION,BOTH,SCRIPT>"ALIGN"                        { RTOKEN(ALIGN_K);}
+<EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN"   { RTOKEN(DATA_SEGMENT_ALIGN);}
+<EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END"     { RTOKEN(DATA_SEGMENT_END);}
 <EXPRESSION,BOTH,SCRIPT>"ADDR"                 { RTOKEN(ADDR);}
 <EXPRESSION,BOTH,SCRIPT>"LOADADDR"             { RTOKEN(LOADADDR);}
-<EXPRESSION,BOTH>"MAX"                 { RTOKEN(MAX); }
-<EXPRESSION,BOTH>"MIN"                 { RTOKEN(MIN); }
+<EXPRESSION,BOTH>"MAX"                 { RTOKEN(MAX_K); }
+<EXPRESSION,BOTH>"MIN"                 { RTOKEN(MIN_K); }
+<EXPRESSION,BOTH>"ASSERT"              { RTOKEN(ASSERT_K); }
 <BOTH,SCRIPT>"ENTRY"                   { RTOKEN(ENTRY);}
+<BOTH,SCRIPT,MRI>"EXTERN"              { RTOKEN(EXTERN);}
 <EXPRESSION,BOTH,SCRIPT>"NEXT"                 { RTOKEN(NEXT);}
 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers"       { RTOKEN(SIZEOF_HEADERS);}
 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS"       { RTOKEN(SIZEOF_HEADERS);}
@@ -256,6 +280,7 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"   { RTOKEN(CREATE_OBJECT_SYMBOLS);}
 <BOTH,SCRIPT>"CONSTRUCTORS"            { RTOKEN( CONSTRUCTORS);}
 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
+<BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
 <BOTH,SCRIPT>"SECTIONS"                { RTOKEN(SECTIONS);}
 <BOTH,SCRIPT>"FILL"                    { RTOKEN(FILL);}
 <BOTH,SCRIPT>"STARTUP"         { RTOKEN(STARTUP);}
@@ -272,6 +297,7 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 <BOTH,SCRIPT>"NOFLOAT"         { RTOKEN(NOFLOAT);}
 <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS"  { RTOKEN(NOCROSSREFS);}
 <BOTH,SCRIPT>"OVERLAY"                 { RTOKEN(OVERLAY); }
+<BOTH,SCRIPT>"SORT"                    { RTOKEN(SORT); }
 <EXPRESSION,BOTH,SCRIPT>"NOLOAD"       { RTOKEN(NOLOAD);}
 <EXPRESSION,BOTH,SCRIPT>"DSECT"                { RTOKEN(DSECT);}
 <EXPRESSION,BOTH,SCRIPT>"COPY"         { RTOKEN(COPY);}
@@ -285,9 +311,10 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 <BOTH,SCRIPT>"PHDRS"                   { RTOKEN (PHDRS); }
 <EXPRESSION,BOTH,SCRIPT>"AT"                   { RTOKEN(AT);}
 <EXPRESSION,BOTH,SCRIPT>"PROVIDE"              { RTOKEN(PROVIDE); }
-<MRI>"#".*\n?\r?               { ++ lineno; }
+<EXPRESSION,BOTH,SCRIPT>"KEEP"         { RTOKEN(KEEP); }
+<EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE"        { RTOKEN(EXCLUDE_FILE); }
+<MRI>"#".*\n?                  { ++ lineno; }
 <MRI>"\n"                      { ++ lineno;  RTOKEN(NEWLINE); }
-<MRI>"\r"                      { ++ lineno;  RTOKEN(NEWLINE); }
 <MRI>"*".*                     { /* Mri comment line */ }
 <MRI>";".*                     { /* Mri comment line */ }
 <MRI>"END"                      { RTOKEN(ENDWORD); }
@@ -303,7 +330,6 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 <MRI>"NAME"                     { RTOKEN(NAMEWORD); }
 <MRI>"FORMAT"                   { RTOKEN(FORMAT); }
 <MRI>"CASE"                     { RTOKEN(CASE); }
-<MRI>"EXTERN"                   { RTOKEN(EXTERN); }
 <MRI>"START"                    { RTOKEN(START); }
 <MRI>"LIST".*                   { RTOKEN(LIST); /* LIST and ignore to end of line */ }
 <MRI>"SECT"                    { RTOKEN(SECT); }
@@ -329,31 +355,45 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 
 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
 /* Filename without commas, needed to parse mri stuff */
-                                yylval.name = buystring(yytext); 
+                                yylval.name = xstrdup(yytext); 
                                  return NAME;
                                }
 
 
 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}*        {
-                                yylval.name = buystring(yytext); 
+                                yylval.name = xstrdup(yytext); 
                                  return NAME;
                                }
 <BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
-                                 yylval.name = buystring (yytext + 2);
+                                 yylval.name = xstrdup (yytext + 2);
                                  return LNAME;
                                }
-<SCRIPT>{WILDCHAR}* { yylval.name = buystring(yytext); return NAME; }
+<SCRIPT>{WILDCHAR}* {
+               /* Annoyingly, this pattern can match comments, and we have
+                  longest match issues to consider.  So if the first two
+                  characters are a comment opening, put the input back and
+                  try again.  */
+               if (yytext[0] == '/' && yytext[1] == '*')
+                 {
+                   yyless(2);
+                   comment ();
+                 }
+               else
+                 {
+                   yylval.name = xstrdup(yytext);
+                   return NAME;
+                 }
+       }
 
-<EXPRESSION,BOTH,SCRIPT>"\""[^\"]*"\"" {
+<EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
                                        /* No matter the state, quotes
                                           give what's inside */
-                                       yylval.name = buystring(yytext+1);
+                                       yylval.name = xstrdup(yytext+1);
                                        yylval.name[yyleng-2] = 0;
                                        return NAME;
                                }
 <BOTH,SCRIPT,EXPRESSION>"\n"           { lineno++;}
-<BOTH,SCRIPT,EXPRESSION>"\r"           { lineno++;}
-<MRI,BOTH,SCRIPT,EXPRESSION>[ \t]
+<MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+   { }
 
 <VERS_NODE,VERS_SCRIPT>[:,;]   { return *yytext; }
 
@@ -361,22 +401,32 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
 
 <VERS_NODE>local               { RTOKEN(LOCAL); }
 
-<VERS_NODE>{V_IDENTIFIER}      { yylval.name = buystring (yytext);
+<VERS_NODE>extern              { RTOKEN(EXTERN); }
+
+<VERS_NODE>{V_IDENTIFIER}      { yylval.name = xstrdup (yytext);
                                  return VERS_IDENTIFIER; }
 
-<VERS_SCRIPT>{V_TAG}           { yylval.name = buystring (yytext);
+<VERS_SCRIPT>{V_TAG}           { yylval.name = xstrdup (yytext);
                                  return VERS_TAG; }
 
 <VERS_START>"{"                        { BEGIN(VERS_SCRIPT); return *yytext; }
 
-<VERS_SCRIPT>"{"               { BEGIN(VERS_NODE); return *yytext; }
-<VERS_SCRIPT,VERS_NODE>"}"     { BEGIN(VERS_SCRIPT); return *yytext; }
+<VERS_SCRIPT>"{"               { BEGIN(VERS_NODE); 
+                                 vers_node_nesting = 0;
+                                 return *yytext;
+                               }
+<VERS_SCRIPT>"}"               { return *yytext; }
+<VERS_NODE>"{"                 { vers_node_nesting++; return *yytext; }
+<VERS_NODE>"}"                 { if (--vers_node_nesting < 0)
+                                   BEGIN(VERS_SCRIPT);
+                                 return *yytext;
+                               }
 
-<VERS_START,VERS_NODE,VERS_SCRIPT>[\n\r]       { lineno++; }
+<VERS_START,VERS_NODE,VERS_SCRIPT>[\n]         { lineno++; }
 
 <VERS_START,VERS_NODE,VERS_SCRIPT>#.*          { /* Eat up comments */ }
 
-<VERS_START,VERS_NODE,VERS_SCRIPT>[ \t]+       { /* Eat up whitespace */ }
+<VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+     { /* Eat up whitespace */ }
 
 <<EOF>> {
   include_stack_ptr--;
@@ -388,11 +438,10 @@ V_IDENTIFIER [*?$_a-zA-Z][*?_a-zA-Z0-9]*
   else 
   {
     yy_switch_to_buffer(include_stack[include_stack_ptr]);
-
   }
-  BEGIN(SCRIPT);
+
   ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
-  lineno = lineno_stack[include_stack_ptr - 1];
+  lineno = lineno_stack[include_stack_ptr];
 
   return END;
 }
@@ -416,13 +465,13 @@ lex_push_file (file, name)
       einfo("%F:includes nested too deeply\n");
     }
   file_name_stack[include_stack_ptr] = name;
-  lineno_stack[include_stack_ptr] = 1;
+  lineno_stack[include_stack_ptr] = lineno;
   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
 
   include_stack_ptr++;
+  lineno = 1;
   yyin = file;
   yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
-  BEGIN (SCRIPT);
 }
 
 /* Return a newly created flex input buffer containing STRING,
@@ -430,7 +479,7 @@ lex_push_file (file, name)
 
 static YY_BUFFER_STATE 
 yy_create_string_buffer (string, size)
-     CONST char *string;
+     const char *string;
      size_t size;
 {
   YY_BUFFER_STATE b;
@@ -451,6 +500,11 @@ yy_create_string_buffer (string, size)
   b->yy_n_chars = size+1;
   b->yy_buf_pos = &b->yy_ch_buf[1];
 
+  b->yy_is_our_buffer = 1;
+  b->yy_is_interactive = 0;
+  b->yy_at_bol = 1;
+  b->yy_fill_buffer = 0;
+
   /* flex 2.4.7 changed the interface.  FIXME: We should not be using
      a flex internal interface in the first place!  */
 #ifdef YY_BUFFER_NEW
@@ -467,7 +521,7 @@ yy_create_string_buffer (string, size)
 
 void
 lex_redirect (string)
-     CONST char *string;
+     const char *string;
 {
   YY_BUFFER_STATE tmp;
 
@@ -477,12 +531,12 @@ lex_redirect (string)
       einfo("%F: macros nested too deeply\n");
     }
   file_name_stack[include_stack_ptr] = "redirect";
-  lineno_stack[include_stack_ptr] = 0;
+  lineno_stack[include_stack_ptr] = lineno;
   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
   include_stack_ptr++;
+  lineno = 1;
   tmp = yy_create_string_buffer (string, strlen (string));
   yy_switch_to_buffer (tmp);
-  BEGIN (SCRIPT);
 }
 \f
 /* Functions to switch to a different flex start condition,
@@ -557,12 +611,12 @@ yy_input (buf, result, max_size)
      int max_size;
 {
   *result = 0; 
-  if (yy_current_buffer->yy_input_file)
+  if (YY_CURRENT_BUFFER->yy_input_file)
     {
       if (yyin)
        {
-         *result = read (fileno (yyin), (char *) buf, max_size);
-         if (*result < 0
+         *result = fread ((char *) buf, 1, max_size, yyin);
+         if (*result < max_size && ferror (yyin)
            einfo ("%F%P: read in flex scanner failed\n");
        }
     }
@@ -580,7 +634,7 @@ comment ()
     c = input();
     while (c != '*' && c != EOF) 
     {
-      if (c == '\n' || c == '\r')
+      if (c == '\n')
        lineno++;
       c = input();
     }
@@ -594,7 +648,7 @@ comment ()
        break;                  /* found the end */
     }
 
-    if (c == '\n' || c == '\r')
+    if (c == '\n')
       lineno++;
 
     if (c == EOF)
@@ -624,7 +678,7 @@ lex_warn_invalid (where, what)
       einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
     }
 
-  if (! isprint ((unsigned char) *what))
+  if (! ISPRINT (*what))
     {
       sprintf (buf, "\\%03o", (unsigned int) *what);
       what = buf;