Add completion for operations
[deliverable/binutils-gdb.git] / gdb / parser-defs.h
index 2c1ea15d05e7d9fae21c763d34b84f011e65bb51..9f70ff9dca7aa3a005dd9125df65e0f36b723ed8 100644 (file)
@@ -1,6 +1,6 @@
 /* Parser definitions for GDB.
 
-   Copyright (C) 1986-2019 Free Software Foundation, Inc.
+   Copyright (C) 1986-2021 Free Software Foundation, Inc.
 
    Modified from expread.y by the Department of Computer Science at the
    State University of New York at Buffalo.
 #if !defined (PARSER_DEFS_H)
 #define PARSER_DEFS_H 1
 
-#include "common/vec.h"
 #include "expression.h"
+#include "symtab.h"
+#include "expop.h"
 
 struct block;
 struct language_defn;
 struct internalvar;
+class innermost_block_tracker;
 
-extern int parser_debug;
+extern bool parser_debug;
 
 /* A class that can be used to build a "struct expression".  */
 
@@ -62,6 +64,13 @@ struct expr_builder
     return expout->language_defn;
   }
 
+  /* Set the root operation of the expression that is currently being
+     built.  */
+  void set_operation (expr::operation_up &&op)
+  {
+    expout->op = std::move (op);
+  }
+
   /* The size of the expression above.  */
 
   size_t expout_size;
@@ -85,6 +94,11 @@ struct expr_completion_state
      field name.  It is -1 if no dereference operation was found.  */
   int expout_last_struct = -1;
 
+  /* The last struct expression directly before a '.' or '->'.  This
+     is set when parsing and is only used when completing a field
+     name.  It is nullptr if no dereference operation was found.  */
+  expr::structop_base_operation *expout_last_op = nullptr;
+
   /* If we are completing a tagged type name, this will be nonzero.  */
   enum type_code expout_tag_completion_type = TYPE_CODE_UNDEF;
 
@@ -107,13 +121,17 @@ struct parser_state : public expr_builder
                CORE_ADDR context_pc,
                int comma,
                const char *input,
-               int completion)
+               int completion,
+               innermost_block_tracker *tracker,
+               bool void_p)
     : expr_builder (lang, gdbarch),
       expression_context_block (context_block),
       expression_context_pc (context_pc),
       comma_terminates (comma),
       lexptr (input),
-      parse_completion (completion)
+      parse_completion (completion),
+      block_tracker (tracker),
+      void_context_p (void_p)
   {
   }
 
@@ -144,6 +162,11 @@ struct parser_state : public expr_builder
 
   void mark_struct_expression ();
 
+  /* Mark the given operation as the starting location of a structure
+     expression.  This is used when completing on field names.  */
+
+  void mark_struct_expression (expr::structop_base_operation *op);
+
   /* 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.  */
@@ -186,6 +209,12 @@ struct parser_state : public expr_builder
   /* Completion state is updated here.  */
   expr_completion_state m_completion_state;
 
+  /* The innermost block tracker.  */
+  innermost_block_tracker *block_tracker;
+
+  /* True if no value is expected from the expression.  */
+  bool void_context_p;
+
 private:
 
   /* Data structure for saving values of arglist_len for function calls whose
@@ -200,21 +229,12 @@ private:
 class innermost_block_tracker
 {
 public:
-  innermost_block_tracker ()
-    : m_types (INNERMOST_BLOCK_FOR_SYMBOLS),
+  innermost_block_tracker (innermost_block_tracker_types types
+                          = INNERMOST_BLOCK_FOR_SYMBOLS)
+    : m_types (types),
       m_innermost_block (NULL)
   { /* Nothing.  */ }
 
-  /* Reset the currently stored innermost block.  Usually called before
-     parsing a new expression.  As the most common case is that we only
-     want to gather the innermost block for symbols in an expression, this
-     becomes the default block tracker type.  */
-  void reset (innermost_block_tracker_types t = INNERMOST_BLOCK_FOR_SYMBOLS)
-  {
-    m_types = t;
-    m_innermost_block = NULL;
-  }
-
   /* 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
@@ -246,12 +266,6 @@ private:
   const struct block *m_innermost_block;
 };
 
-/* The innermost context required by the stack and register variables
-   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;
-
 /* A string token, either a char-string or bit-string.  Char-strings are
    used, for example, for the names of symbols.  */
 
@@ -299,40 +313,6 @@ struct objc_class_str
     int theclass;
   };
 
-/* For parsing of complicated types.
-   An array should be preceded in the list by the size of the array.  */
-enum type_pieces
-  {
-    tp_end = -1, 
-    tp_pointer, 
-    tp_reference, 
-    tp_rvalue_reference,
-    tp_array, 
-    tp_function,
-    tp_function_with_arguments,
-    tp_const, 
-    tp_volatile, 
-    tp_space_identifier,
-    tp_type_stack,
-    tp_kind
-  };
-/* The stack can contain either an enum type_pieces or an int.  */
-union type_stack_elt
-  {
-    enum type_pieces piece;
-    int int_val;
-    struct type_stack *stack_val;
-    std::vector<struct type *> *typelist_val;
-  };
-
-/* The type stack is an instance of this structure.  */
-
-struct type_stack
-{
-  /* Elements on the stack.  */
-  std::vector<union type_stack_elt> elements;
-};
-
 /* Reverse an expression from suffix form (in which it is constructed)
    to prefix form (in which we can conveniently print or execute it).
    Ordinarily this always returns -1.  However, if LAST_STRUCT
@@ -372,36 +352,32 @@ extern void write_exp_msymbol (struct expr_builder *,
 
 extern void write_dollar_variable (struct parser_state *, struct stoken str);
 
-extern const char *find_template_name_end (const char *);
-
-extern char *copy_name (struct stoken);
-
-extern void insert_type (enum type_pieces);
-
-extern void push_type (enum type_pieces);
-
-extern void push_type_int (int);
-
-extern void insert_type_address_space (struct expr_builder *, char *);
-
-extern enum type_pieces pop_type (void);
-
-extern int pop_type_int (void);
-
-extern struct type_stack *get_type_stack (void);
+/* Write a reference to a symbol to the expression being built in PS.
+   NAME is the name of the symbol to write; SYM is the symbol.  If SYM
+   is nullptr (meaning the 'symbol' member), a minimal symbol will be
+   searched for and used if available.  Throws an exception if SYM is
+   nullptr and no minimal symbol can be found.  */
 
-extern struct type_stack *append_type_stack (struct type_stack *to,
-                                            struct type_stack *from);
+extern void write_exp_symbol_reference (struct parser_state *ps,
+                                       const char *name,
+                                       struct block_symbol sym);
 
-extern void push_type_stack (struct type_stack *stack);
+extern const char *find_template_name_end (const char *);
 
-extern void push_typelist (std::vector<struct type *> *typelist);
+extern std::string copy_name (struct stoken);
 
 extern int dump_subexp (struct expression *, struct ui_file *, int);
 
 extern int dump_subexp_body_standard (struct expression *, 
                                      struct ui_file *, int);
 
+/* Dump (to STREAM) a function call like expression at position ELT in the
+   expression array EXP.  Return a new value for ELT just after the
+   function call expression.  */
+
+extern int dump_subexp_body_funcall (struct expression *exp,
+                                    struct ui_file *stream, int elt);
+
 extern void operator_length (const struct expression *, int, int *, int *);
 
 extern void operator_length_standard (const struct expression *, int, int *,
@@ -412,14 +388,6 @@ extern int operator_check_standard (struct expression *exp, int pos,
                                      (struct objfile *objfile, void *data),
                                    void *data);
 
-extern const char *op_name_standard (enum exp_opcode);
-
-extern struct type *follow_types (struct type *);
-
-extern type_instance_flags follow_type_instance_flags ();
-
-extern void null_post_parser (expression_up *, int, int);
-
 extern bool parse_float (const char *p, int len,
                         const struct type *type, gdb_byte *data);
 \f
@@ -480,12 +448,6 @@ struct exp_descriptor
                                                void *data),
                           void *data);
 
-    /* Name of this operator for dumping purposes.
-       The returned value should never be NULL, even if EXP_OPCODE is
-       an unknown opcode (a string containing an image of the numeric
-       value of the opcode can be returned, for instance).  */
-    const char *(*op_name) (enum exp_opcode);
-
     /* Dump the rest of this (prefix) expression after the operator
        itself has been printed.  See dump_subexp_body_standard in
        (expprint.c).  */
@@ -510,6 +472,15 @@ extern void print_subexp (struct expression *, int *, struct ui_file *,
 extern void print_subexp_standard (struct expression *, int *, 
                                   struct ui_file *, enum precedence);
 
+/* Print a function call like expression to STREAM.  This is called as a
+   helper function by which point the expression node identifying this as a
+   function call has already been stripped off and POS should point to the
+   number of function call arguments.  EXP is the object containing the
+   list of expression elements.  */
+
+extern void print_subexp_funcall (struct expression *exp, int *pos,
+                                 struct ui_file *stream);
+
 /* Function used to avoid direct calls to fprintf
    in the code generated by the bison parser.  */
 
This page took 0.041004 seconds and 4 git commands to generate.