Move comma_terminates global to parser_state
[deliverable/binutils-gdb.git] / gdb / parser-defs.h
index 5b38477895ab5decf4ce7dec7c3c768b89d9f18e..f2bb18fd9c74ab8a2bf9a87c2232d633721a72da 100644 (file)
@@ -23,7 +23,7 @@
 #if !defined (PARSER_DEFS_H)
 #define PARSER_DEFS_H 1
 
-#include "vec.h"
+#include "common/vec.h"
 #include "expression.h"
 
 struct block;
@@ -32,23 +32,35 @@ struct internalvar;
 
 extern int parser_debug;
 
-#define parse_gdbarch(ps) ((ps)->expout->gdbarch)
-#define parse_language(ps) ((ps)->expout->language_defn)
+/* A class that can be used to build a "struct expression".  */
 
-struct parser_state
+struct expr_builder
 {
-  /* Constructor.  INITIAL_SIZE is the initial size of the expout
-     array.  LANG is the language used to parse the expression.  And
-     GDBARCH is the gdbarch to use during parsing.  */
+  /* Constructor.  LANG is the language used to parse the expression.
+     And GDBARCH is the gdbarch to use during parsing.  */
 
-  parser_state (size_t initial_size, const struct language_defn *lang,
+  expr_builder (const struct language_defn *lang,
                struct gdbarch *gdbarch);
 
-  DISABLE_COPY_AND_ASSIGN (parser_state);
+  DISABLE_COPY_AND_ASSIGN (expr_builder);
 
   /* Resize the allocated expression to the correct size, and return
      it as an expression_up -- passing ownership to the caller.  */
-  expression_up release ();
+  ATTRIBUTE_UNUSED_RESULT expression_up release ();
+
+  /* Return the gdbarch that was passed to the constructor.  */
+
+  struct gdbarch *gdbarch ()
+  {
+    return expout->gdbarch;
+  }
+
+  /* Return the language that was passed to the constructor.  */
+
+  const struct language_defn *language ()
+  {
+    return expout->language_defn;
+  }
 
   /* The size of the expression above.  */
 
@@ -64,34 +76,45 @@ struct parser_state
   size_t expout_ptr;
 };
 
-/* If this is nonzero, this block is used as the lexical context
-   for symbol names.  */
+/* An instance of this type is instantiated during expression parsing,
+   and passed to the appropriate parser.  It holds both inputs to the
+   parser, and result.  */
+
+struct parser_state : public expr_builder
+{
+  /* Constructor.  LANG is the language used to parse the expression.
+     And GDBARCH is the gdbarch to use during parsing.  */
+
+  parser_state (const struct language_defn *lang,
+               struct gdbarch *gdbarch,
+               const struct block *context_block,
+               CORE_ADDR context_pc,
+               int comma)
+    : expr_builder (lang, gdbarch),
+      expression_context_block (context_block),
+      expression_context_pc (context_pc),
+      comma_terminates (comma)
+  {
+  }
+
+  DISABLE_COPY_AND_ASSIGN (parser_state);
 
-extern const struct block *expression_context_block;
+  /* If this is nonzero, this block is used as the lexical context for
+     symbol names.  */
 
-/* If expression_context_block is non-zero, then this is the PC within
-   the block that we want to evaluate expressions at.  When debugging
-   C or C++ code, we use this to find the exact line we're at, and
-   then look up the macro definitions active at that point.  */
-extern CORE_ADDR expression_context_pc;
+  const struct block * const expression_context_block;
 
-/* While parsing expressions we need to track the innermost lexical block
-   that we encounter.  In some situations we need to track the innermost
-   block just for symbols, and in other situations we want to track the
-   innermost block for symbols and registers.  These flags are used by the
-   innermost block tracker to control which blocks we consider for the
-   innermost block.  These flags can be combined together as needed.  */
+  /* If expression_context_block is non-zero, then this is the PC
+     within the block that we want to evaluate expressions at.  When
+     debugging C or C++ code, we use this to find the exact line we're
+     at, and then look up the macro definitions active at that
+     point.  */
+  const CORE_ADDR expression_context_pc;
 
-enum innermost_block_tracker_type
-{
-  /* Track the innermost block for symbols within an expression.  */
-  INNERMOST_BLOCK_FOR_SYMBOLS = (1 << 0),
+  /* Nonzero means stop parsing on first comma (if not within parentheses).  */
 
-  /* Track the innermost block for registers within an expression.  */
-  INNERMOST_BLOCK_FOR_REGISTERS = (1 << 1)
+  int comma_terminates;
 };
-DEF_ENUM_FLAGS_TYPE (enum innermost_block_tracker_type,
-                    innermost_block_tracker_types);
 
 /* When parsing expressions we track the innermost block that was
    referenced.  */
@@ -146,8 +169,9 @@ private:
 };
 
 /* The innermost context required by the stack and register variables
-   we've encountered so far.  This should be cleared before parsing an
-   expression, and queried once the parse is complete.  */
+   we've encountered so far.  This is cleared by the expression
+   parsing functions before parsing an expression, and can queried
+   once the parse is complete.  */
 extern innermost_block_tracker innermost_block;
 
 /* Number of arguments seen so far in innermost function call.  */
@@ -214,7 +238,8 @@ enum type_pieces
     tp_const, 
     tp_volatile, 
     tp_space_identifier,
-    tp_type_stack
+    tp_type_stack,
+    tp_kind
   };
 /* The stack can contain either an enum type_pieces or an int.  */
 union type_stack_elt
@@ -242,36 +267,36 @@ struct type_stack
 
 extern int prefixify_expression (struct expression *expr);
 
-extern void write_exp_elt_opcode (struct parser_state *, enum exp_opcode);
+extern void write_exp_elt_opcode (struct expr_builder *, enum exp_opcode);
 
-extern void write_exp_elt_sym (struct parser_state *, struct symbol *);
+extern void write_exp_elt_sym (struct expr_builder *, struct symbol *);
 
-extern void write_exp_elt_longcst (struct parser_state *, LONGEST);
+extern void write_exp_elt_longcst (struct expr_builder *, LONGEST);
 
-extern void write_exp_elt_floatcst (struct parser_state *, const gdb_byte *);
+extern void write_exp_elt_floatcst (struct expr_builder *, const gdb_byte *);
 
-extern void write_exp_elt_type (struct parser_state *, struct type *);
+extern void write_exp_elt_type (struct expr_builder *, struct type *);
 
-extern void write_exp_elt_intern (struct parser_state *, struct internalvar *);
+extern void write_exp_elt_intern (struct expr_builder *, struct internalvar *);
 
-extern void write_exp_string (struct parser_state *, struct stoken);
+extern void write_exp_string (struct expr_builder *, struct stoken);
 
-void write_exp_string_vector (struct parser_state *, int type,
+void write_exp_string_vector (struct expr_builder *, int type,
                              struct stoken_vector *vec);
 
-extern void write_exp_bitstring (struct parser_state *, struct stoken);
+extern void write_exp_bitstring (struct expr_builder *, struct stoken);
 
-extern void write_exp_elt_block (struct parser_state *, const struct block *);
+extern void write_exp_elt_block (struct expr_builder *, const struct block *);
 
-extern void write_exp_elt_objfile (struct parser_state *,
+extern void write_exp_elt_objfile (struct expr_builder *,
                                   struct objfile *objfile);
 
-extern void write_exp_msymbol (struct parser_state *,
+extern void write_exp_msymbol (struct expr_builder *,
                               struct bound_minimal_symbol);
 
 extern void write_dollar_variable (struct parser_state *, struct stoken str);
 
-extern void mark_struct_expression (struct parser_state *);
+extern void mark_struct_expression (struct expr_builder *);
 
 extern const char *find_template_name_end (const char *);
 
@@ -287,7 +312,7 @@ extern void push_type (enum type_pieces);
 
 extern void push_type_int (int);
 
-extern void insert_type_address_space (struct parser_state *, char *);
+extern void insert_type_address_space (struct expr_builder *, char *);
 
 extern enum type_pieces pop_type (void);
 
@@ -336,14 +361,6 @@ extern const char *lexptr;
 /* After a token has been recognized, this variable points to it.
    Currently used only for error reporting.  */
 extern const char *prev_lexptr;
-
-/* Current depth in parentheses within the expression.  */
-
-extern int paren_depth;
-
-/* Nonzero means stop parsing on first comma (if not within parentheses).  */
-
-extern int comma_terminates;
 \f
 /* These codes indicate operator precedences for expression printing,
    least tightly binding first.  */
@@ -442,11 +459,5 @@ extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile);
 extern void mark_completion_tag (enum type_code, const char *ptr,
                                 int length);
 
-/* Reallocate the `expout' pointer inside PS so that it can accommodate
-   at least LENELT expression elements.  This function does nothing if
-   there is enough room for the elements.  */
-
-extern void increase_expout_size (struct parser_state *ps, size_t lenelt);
-
 #endif /* PARSER_DEFS_H */
 
This page took 0.028476 seconds and 4 git commands to generate.