symlist.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Lists of symbols for Bison
  2. Copyright (C) 2002, 2005-2007, 2009-2015, 2018-2019 Free Software
  3. Foundation, Inc.
  4. This file is part of Bison, the GNU Compiler Compiler.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef SYMLIST_H_
  16. # define SYMLIST_H_
  17. # include "location.h"
  18. # include "scan-code.h"
  19. # include "symtab.h"
  20. # include "named-ref.h"
  21. /* A list of symbols, used during the parsing to store the rules. */
  22. typedef struct symbol_list
  23. {
  24. /**
  25. * Whether this node contains a symbol, a semantic type, a \c <*>, or a
  26. * \c <>.
  27. */
  28. enum {
  29. SYMLIST_SYMBOL,
  30. SYMLIST_TYPE
  31. } content_type;
  32. union {
  33. /**
  34. * The symbol or \c NULL iff
  35. * <tt>symbol_list::content_type = SYMLIST_SYMBOL</tt>.
  36. */
  37. symbol *sym;
  38. /**
  39. * The semantic type iff <tt>symbol_list::content_type = SYMLIST_TYPE</tt>.
  40. */
  41. semantic_type *sem_type;
  42. } content;
  43. location location;
  44. /* Named reference. */
  45. named_ref *named_ref;
  46. /* Proper location of the symbol, not all the rule */
  47. location sym_loc;
  48. /* If this symbol is the generated lhs for a midrule but this is the rule in
  49. whose rhs it appears, MIDRULE = a pointer to that midrule. */
  50. struct symbol_list *midrule;
  51. /* If this symbol is the generated lhs for a midrule and this is that
  52. midrule, MIDRULE_PARENT_RULE = a pointer to the rule in whose rhs it
  53. appears, and MIDRULE_PARENT_RHS_INDEX = its rhs index (1-origin) in the
  54. parent rule. */
  55. struct symbol_list *midrule_parent_rule;
  56. int midrule_parent_rhs_index;
  57. /* ---------------------------------------------- */
  58. /* Apply to the rule (attached to the LHS only). */
  59. /* ---------------------------------------------- */
  60. /* Precedence/associativity. */
  61. symbol *ruleprec;
  62. /* The action is attached to the LHS of a rule, but action properties for
  63. * each RHS are also stored here. */
  64. code_props action_props;
  65. /* The location of the first %empty for this rule, or \a
  66. empty_location. */
  67. location percent_empty_loc;
  68. int dprec;
  69. location dprec_location;
  70. int merger;
  71. location merger_declaration_location;
  72. /* Counts of the number of expected conflicts for this rule, or -1 if none
  73. given. */
  74. int expected_sr_conflicts;
  75. int expected_rr_conflicts;
  76. /* The list. */
  77. struct symbol_list *next;
  78. } symbol_list;
  79. /** Create a list containing \c sym at \c loc. */
  80. symbol_list *symbol_list_sym_new (symbol *sym, location loc);
  81. /** Create a list containing \c type_name at \c loc. */
  82. symbol_list *symbol_list_type_new (uniqstr type_name, location loc);
  83. /** Assign the type \c type_name to all the members of \c syms.
  84. ** \returns \c syms */
  85. symbol_list *symbol_list_type_set (symbol_list *syms,
  86. uniqstr type_name, location loc);
  87. /** Print this list.
  88. \pre For every node \c n in the list, <tt>n->content_type =
  89. SYMLIST_SYMBOL</tt>. */
  90. void symbol_list_syms_print (const symbol_list *l, FILE *f);
  91. /** Prepend \c node to \c list. */
  92. symbol_list *symbol_list_prepend (symbol_list *list, symbol_list *node);
  93. /** Append \c node to \c list. */
  94. symbol_list *symbol_list_append (symbol_list *list, symbol_list *node);
  95. /** Free \c list, but not the items it contains. */
  96. void symbol_list_free (symbol_list *list);
  97. /** Return the length of \c l. */
  98. int symbol_list_length (symbol_list const *l);
  99. /** Get item \c n in symbol list \c l.
  100. ** \pre 0 <= n
  101. ** \post res != NULL
  102. **/
  103. symbol_list *symbol_list_n_get (symbol_list *l, int n);
  104. /* Get the data type (alternative in the union) of the value for
  105. symbol N in rule RULE. */
  106. uniqstr symbol_list_n_type_name_get (symbol_list *l, int n);
  107. /* Check whether the node is a border element of a rule. */
  108. bool symbol_list_null (symbol_list *node);
  109. /** Set the \c \%destructor or \c \%printer for \c node as \c cprops. */
  110. void symbol_list_code_props_set (symbol_list *node, code_props_type kind,
  111. code_props const *cprops);
  112. #endif /* !SYMLIST_H_ */