+ /* 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. */
+
+ size_t expout_size;
+
+ /* The expression related to this parser state. */
+
+ expression_up expout;
+
+ /* The number of elements already in the expression. This is used
+ to know where to put new elements. */
+
+ size_t expout_ptr;
+};
+
+/* This is used for expression completion. */
+
+struct expr_completion_state
+{
+ /* The index of the last struct expression directly before a '.' or
+ '->'. This is set when parsing and is only used when completing a
+ field name. It is -1 if no dereference operation was found. */
+ int expout_last_struct = -1;
+
+ /* If we are completing a tagged type name, this will be nonzero. */
+ enum type_code expout_tag_completion_type = TYPE_CODE_UNDEF;
+
+ /* The token for tagged type name completion. */
+ gdb::unique_xmalloc_ptr<char> expout_completion_name;
+};
+
+/* 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,
+ const char *input,
+ int completion,
+ innermost_block_tracker *tracker)
+ : expr_builder (lang, gdbarch),
+ expression_context_block (context_block),
+ expression_context_pc (context_pc),
+ comma_terminates (comma),
+ lexptr (input),
+ parse_completion (completion),
+ block_tracker (tracker)
+ {
+ }
+
+ DISABLE_COPY_AND_ASSIGN (parser_state);
+
+ /* Begin counting arguments for a function call,
+ saving the data about any containing call. */
+
+ void start_arglist ()
+ {
+ m_funcall_chain.push_back (arglist_len);
+ arglist_len = 0;
+ }
+
+ /* Return the number of arguments in a function call just terminated,
+ and restore the data for the containing function call. */
+
+ int end_arglist ()
+ {
+ int val = arglist_len;
+ arglist_len = m_funcall_chain.back ();
+ m_funcall_chain.pop_back ();
+ return val;
+ }
+
+ /* Mark the current index as the starting location of a structure
+ expression. This is used when completing on field names. */
+
+ void mark_struct_expression ();
+
+ /* Indicate that the current parser invocation is completing a tag.
+ TAG is the type code of the tag, and PTR and LENGTH represent the
+ start of the tag name. */
+
+ void mark_completion_tag (enum type_code tag, const char *ptr, int length);
+
+
+ /* If this is nonzero, this block is used as the lexical context for
+ symbol names. */
+
+ const struct block * const expression_context_block;
+
+ /* 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;
+
+ /* Nonzero means stop parsing on first comma (if not within parentheses). */
+
+ int comma_terminates;
+
+ /* During parsing of a C expression, the pointer to the next character
+ is in this variable. */
+
+ const char *lexptr;
+
+ /* After a token has been recognized, this variable points to it.
+ Currently used only for error reporting. */
+ const char *prev_lexptr = nullptr;
+
+ /* Number of arguments seen so far in innermost function call. */
+
+ int arglist_len = 0;
+
+ /* True if parsing an expression to attempt completion. */
+ int parse_completion;
+
+ /* Completion state is updated here. */
+ expr_completion_state m_completion_state;
+
+ /* The innermost block tracker. */
+ innermost_block_tracker *block_tracker;
+
+private:
+
+ /* Data structure for saving values of arglist_len for function calls whose
+ arguments contain other function calls. */
+
+ std::vector<int> m_funcall_chain;
+};
+
+/* When parsing expressions we track the innermost block that was
+ referenced. */
+
+class innermost_block_tracker
+{
+public:
+ innermost_block_tracker (innermost_block_tracker_types types
+ = INNERMOST_BLOCK_FOR_SYMBOLS)
+ : m_types (types),
+ m_innermost_block (NULL)
+ { /* Nothing. */ }
+
+ /* Update the stored innermost block if the new block B is more inner
+ than the currently stored block, or if no block is stored yet. The
+ type T tells us whether the block B was for a symbol or for a
+ register. The stored innermost block is only updated if the type T is
+ a type we are interested in, the types we are interested in are held
+ in M_TYPES and set during RESET. */
+ void update (const struct block *b, innermost_block_tracker_types t);
+
+ /* Overload of main UPDATE method which extracts the block from BS. */
+ void update (const struct block_symbol &bs)
+ {
+ update (bs.block, INNERMOST_BLOCK_FOR_SYMBOLS);
+ }
+
+ /* Return the stored innermost block. Can be nullptr if no symbols or
+ registers were found during an expression parse, and so no innermost
+ block was defined. */
+ const struct block *block () const
+ {
+ return m_innermost_block;
+ }
+
+private:
+ /* The type of innermost block being looked for. */
+ innermost_block_tracker_types m_types;
+
+ /* The currently stored innermost block found while parsing an
+ expression. */
+ const struct block *m_innermost_block;
+};