]> git.saurik.com Git - bison.git/blobdiff - src/symtab.c
* src/gram.c (rule_rhs_print_xml): Now static, since it isn't used
[bison.git] / src / symtab.c
index 81a938ced42b961280ec6dd4f5e1b6cd384bdf5e..e438e4fc132c0b8598cb3c030982faee0a75a8e9 100644 (file)
@@ -1,24 +1,22 @@
 /* Symbol table manager for Bison.
 
 /* Symbol table manager for Bison.
 
-   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006 Free
+   Copyright (C) 1984, 1989, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free
    Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
    Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
-   Bison is free software; you can redistribute it and/or modify
+   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
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
 
-   Bison is distributed in the hope that it will be useful,
+   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
    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 Bison; see the file COPYING.  If not, write to
-   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include "system.h"
 
 #include <config.h>
 #include "system.h"
@@ -109,9 +107,9 @@ semantic_type_new (uniqstr tag)
   if (s->Attr)                                         \
     fprintf (f, " %s { %s }", #Attr, s->Attr)
 
   if (s->Attr)                                         \
     fprintf (f, " %s { %s }", #Attr, s->Attr)
 
-#define SYMBOL_CODE_PRINT(Attr)                                \
-  if (code_props_code_get (s->Attr))                   \
-    fprintf (f, " %s { %s }", #Attr, code_props_code_get(s->Attr))
+#define SYMBOL_CODE_PRINT(Attr)                         \
+  if (s->Attr.code)                                     \
+    fprintf (f, " %s { %s }", #Attr, s->Attr.code)
 
 void
 symbol_print (symbol *s, FILE *f)
 
 void
 symbol_print (symbol *s, FILE *f)
@@ -170,19 +168,35 @@ symbol_type_set (symbol *sym, uniqstr type_name, location loc)
     }
 }
 
     }
 }
 
+/*-----------------------------------.
+| Get the CLASS associated with SYM. |
+`-----------------------------------*/
+
+const char *
+symbol_class_get_string (symbol *sym)
+{
+  if (sym->class)
+    {
+      if (sym->class == token_sym)
+       return "terminal";
+      else if (sym->class == nterm_sym)
+       return "nonterminal";
+    }
+  return "unknown";
+}
+
 
 /*-----------------------------------------.
 | Set the DESTRUCTOR associated with SYM.  |
 `-----------------------------------------*/
 
 void
 
 /*-----------------------------------------.
 | Set the DESTRUCTOR associated with SYM.  |
 `-----------------------------------------*/
 
 void
-symbol_destructor_set (symbol *sym, code_props destructor)
+symbol_destructor_set (symbol *sym, code_props const *destructor)
 {
 {
-  if (code_props_code_get (sym->destructor))
-    symbol_redeclaration (sym, "%destructor",
-                          code_props_location_get (sym->destructor),
-                          code_props_location_get (destructor));
-  sym->destructor = destructor;
+  if (sym->destructor.code)
+    symbol_redeclaration (sym, "%destructor", sym->destructor.location,
+                          destructor->location);
+  sym->destructor = *destructor;
 }
 
 /*------------------------------------------.
 }
 
 /*------------------------------------------.
@@ -190,41 +204,43 @@ symbol_destructor_set (symbol *sym, code_props destructor)
 `------------------------------------------*/
 
 void
 `------------------------------------------*/
 
 void
-semantic_type_destructor_set (semantic_type *type, code_props destructor)
+semantic_type_destructor_set (semantic_type *type,
+                              code_props const *destructor)
 {
 {
-  if (code_props_code_get (type->destructor))
+  if (type->destructor.code)
     semantic_type_redeclaration (type, "%destructor",
     semantic_type_redeclaration (type, "%destructor",
-                                 code_props_location_get (type->destructor),
-                                 code_props_location_get (destructor));
-  type->destructor = destructor;
+                                 type->destructor.location,
+                                 destructor->location);
+  type->destructor = *destructor;
 }
 
 /*---------------------------------------.
 | Get the computed %destructor for SYM.  |
 `---------------------------------------*/
 
 }
 
 /*---------------------------------------.
 | Get the computed %destructor for SYM.  |
 `---------------------------------------*/
 
-code_props
-symbol_destructor_get (symbol *sym)
+code_props const *
+symbol_destructor_get (symbol const *sym)
 {
   /* Per-symbol %destructor.  */
 {
   /* Per-symbol %destructor.  */
-  if (code_props_code_get (sym->destructor))
-    return sym->destructor;
+  if (sym->destructor.code)
+    return &sym->destructor;
 
   /* Per-type %destructor.  */
   if (sym->type_name)
     {
 
   /* Per-type %destructor.  */
   if (sym->type_name)
     {
-      code_props destructor = semantic_type_get (sym->type_name)->destructor;
-      if (code_props_code_get (destructor))
+      code_props const *destructor =
+        &semantic_type_get (sym->type_name)->destructor;
+      if (destructor->code)
         return destructor;
     }
 
   /* Apply default %destructor's only to user-defined symbols.  */
   if (sym->tag[0] == '$' || sym == errtoken)
         return destructor;
     }
 
   /* Apply default %destructor's only to user-defined symbols.  */
   if (sym->tag[0] == '$' || sym == errtoken)
-    return code_props_none;
+    return &code_props_none;
 
   if (sym->type_name)
 
   if (sym->type_name)
-    return default_tagged_destructor;
-  return default_tagless_destructor;
+    return &default_tagged_destructor;
+  return &default_tagless_destructor;
 }
 
 /*--------------------------------------.
 }
 
 /*--------------------------------------.
@@ -232,13 +248,12 @@ symbol_destructor_get (symbol *sym)
 `--------------------------------------*/
 
 void
 `--------------------------------------*/
 
 void
-symbol_printer_set (symbol *sym, code_props printer)
+symbol_printer_set (symbol *sym, code_props const *printer)
 {
 {
-  if (code_props_code_get (sym->printer))
+  if (sym->printer.code)
     symbol_redeclaration (sym, "%printer",
     symbol_redeclaration (sym, "%printer",
-                          code_props_location_get (sym->printer),
-                          code_props_location_get (printer));
-  sym->printer = printer;
+                          sym->printer.location, printer->location);
+  sym->printer = *printer;
 }
 
 /*---------------------------------------.
 }
 
 /*---------------------------------------.
@@ -246,41 +261,40 @@ symbol_printer_set (symbol *sym, code_props printer)
 `---------------------------------------*/
 
 void
 `---------------------------------------*/
 
 void
-semantic_type_printer_set (semantic_type *type, code_props printer)
+semantic_type_printer_set (semantic_type *type, code_props const *printer)
 {
 {
-  if (code_props_code_get (type->printer))
+  if (type->printer.code)
     semantic_type_redeclaration (type, "%printer",
     semantic_type_redeclaration (type, "%printer",
-                                 code_props_location_get (type->printer),
-                                 code_props_location_get (printer));
-  type->printer = printer;
+                                 type->printer.location, printer->location);
+  type->printer = *printer;
 }
 
 /*------------------------------------.
 | Get the computed %printer for SYM.  |
 `------------------------------------*/
 
 }
 
 /*------------------------------------.
 | Get the computed %printer for SYM.  |
 `------------------------------------*/
 
-code_props
-symbol_printer_get (symbol *sym)
+code_props const *
+symbol_printer_get (symbol const *sym)
 {
   /* Per-symbol %printer.  */
 {
   /* Per-symbol %printer.  */
-  if (code_props_code_get (sym->printer))
-    return sym->printer;
+  if (sym->printer.code)
+    return &sym->printer;
 
   /* Per-type %printer.  */
   if (sym->type_name)
     {
 
   /* Per-type %printer.  */
   if (sym->type_name)
     {
-      code_props printer = semantic_type_get (sym->type_name)->printer;
-      if (code_props_code_get (printer))
+      code_props const *printer = &semantic_type_get (sym->type_name)->printer;
+      if (printer->code)
         return printer;
     }
 
   /* Apply the default %printer only to user-defined symbols.  */
   if (sym->tag[0] == '$' || sym == errtoken)
         return printer;
     }
 
   /* Apply the default %printer only to user-defined symbols.  */
   if (sym->tag[0] == '$' || sym == errtoken)
-    return code_props_none;
+    return &code_props_none;
 
   if (sym->type_name)
 
   if (sym->type_name)
-    return default_tagged_printer;
-  return default_tagless_printer;
+    return &default_tagged_printer;
+  return &default_tagless_printer;
 }
 
 /*-----------------------------------------------------------------.
 }
 
 /*-----------------------------------------------------------------.
@@ -446,22 +460,20 @@ symbol_check_alias_consistency (symbol *this)
     }
 
 
     }
 
 
-  if (code_props_code_get (orig->destructor)
-      || code_props_code_get (alias->destructor))
+  if (orig->destructor.code || alias->destructor.code)
     {
     {
-      if (code_props_code_get (orig->destructor))
-       symbol_destructor_set (alias, orig->destructor);
+      if (orig->destructor.code)
+       symbol_destructor_set (alias, &orig->destructor);
       else
       else
-       symbol_destructor_set (orig, alias->destructor);
+       symbol_destructor_set (orig, &alias->destructor);
     }
 
     }
 
-  if (code_props_code_get (orig->printer)
-      || code_props_code_get (alias->printer))
+  if (orig->printer.code || alias->printer.code)
     {
     {
-      if (code_props_code_get (orig->printer))
-       symbol_printer_set (alias, orig->printer);
+      if (orig->printer.code)
+       symbol_printer_set (alias, &orig->printer);
       else
       else
-       symbol_printer_set (orig, alias->printer);
+       symbol_printer_set (orig, &alias->printer);
     }
 
   if (alias->prec || orig->prec)
     }
 
   if (alias->prec || orig->prec)
@@ -890,54 +902,53 @@ symbols_pack (void)
 `--------------------------------------------------*/
 
 void
 `--------------------------------------------------*/
 
 void
-default_tagged_destructor_set (code_props destructor)
+default_tagged_destructor_set (code_props const *destructor)
 {
 {
-  if (code_props_code_get (default_tagged_destructor))
+  if (default_tagged_destructor.code)
     {
     {
-      complain_at (code_props_location_get (destructor),
+      complain_at (destructor->location,
                    _("redeclaration for default tagged %%destructor"));
                    _("redeclaration for default tagged %%destructor"));
-      complain_at (code_props_location_get (default_tagged_destructor),
+      complain_at (default_tagged_destructor.location,
                   _("previous declaration"));
     }
                   _("previous declaration"));
     }
-  default_tagged_destructor = destructor;
+  default_tagged_destructor = *destructor;
 }
 
 void
 }
 
 void
-default_tagless_destructor_set (code_props destructor)
+default_tagless_destructor_set (code_props const *destructor)
 {
 {
-  if (code_props_code_get (default_tagless_destructor))
+  if (default_tagless_destructor.code)
     {
     {
-      complain_at (code_props_location_get (destructor),
+      complain_at (destructor->location,
                    _("redeclaration for default tagless %%destructor"));
                    _("redeclaration for default tagless %%destructor"));
-      complain_at (code_props_location_get (default_tagless_destructor),
+      complain_at (default_tagless_destructor.location,
                   _("previous declaration"));
     }
                   _("previous declaration"));
     }
-  default_tagless_destructor = destructor;
+  default_tagless_destructor = *destructor;
 }
 
 void
 }
 
 void
-default_tagged_printer_set (code_props printer)
+default_tagged_printer_set (code_props const *printer)
 {
 {
-  if (code_props_code_get (default_tagged_printer))
+  if (default_tagged_printer.code)
     {
     {
-      complain_at (code_props_location_get (printer),
+      complain_at (printer->location,
                    _("redeclaration for default tagged %%printer"));
                    _("redeclaration for default tagged %%printer"));
-      complain_at (code_props_location_get (default_tagged_printer),
+      complain_at (default_tagged_printer.location,
                   _("previous declaration"));
     }
                   _("previous declaration"));
     }
-  default_tagged_printer = printer;
+  default_tagged_printer = *printer;
 }
 
 void
 }
 
 void
-default_tagless_printer_set (code_props printer)
+default_tagless_printer_set (code_props const *printer)
 {
 {
-  if (code_props_code_get (default_tagless_printer))
+  if (default_tagless_printer.code)
     {
     {
-      complain_at (code_props_location_get (printer),
+      complain_at (printer->location,
                    _("redeclaration for default tagless %%printer"));
                    _("redeclaration for default tagless %%printer"));
-      complain_at (code_props_location_get (default_tagless_printer),
+      complain_at (default_tagless_printer.location,
                   _("previous declaration"));
     }
                   _("previous declaration"));
     }
-  default_tagless_printer = printer;
+  default_tagless_printer = *printer;
 }
 }
-