[gdb/testsuite] Fix gdb.base/coredump-filter-build-id.exp with older eu-unstrip
[deliverable/binutils-gdb.git] / gdb / f-exp.y
index 896296d7203350c7db515bfeb52de017e5d1f53b..6608831a9a53807692f0225d185a30b8644363c9 100644 (file)
@@ -1,6 +1,6 @@
 
 /* YACC parser for Fortran expressions, for GDB.
-   Copyright (C) 1986-2015 Free Software Foundation, Inc.
+   Copyright (C) 1986-2021 Free Software Foundation, Inc.
 
    Contributed by Motorola.  Adapted from the C parser by Farooq Butt
    (fmbutt@engage.sps.mot.com).
 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
 #include "block.h"
 #include <ctype.h>
+#include <algorithm>
+#include "type-stack.h"
+#include "f-exp.h"
 
-#define parse_type(ps) builtin_type (parse_gdbarch (ps))
-#define parse_f_type(ps) builtin_f_type (parse_gdbarch (ps))
-
-/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
-   as well as gratuitiously global symbol names, so we can have multiple
-   yacc generated parsers in gdb.  Note that these are only the variables
-   produced by yacc.  If other parser generators (bison, byacc, etc) produce
-   additional global names that conflict at link time, then those parser
-   generators need to be fixed instead of adding those names to this list.  */
-
-#define        yymaxdepth f_maxdepth
-#define        yyparse f_parse_internal
-#define        yylex   f_lex
-#define        yyerror f_error
-#define        yylval  f_lval
-#define        yychar  f_char
-#define        yydebug f_debug
-#define        yypact  f_pact  
-#define        yyr1    f_r1                    
-#define        yyr2    f_r2                    
-#define        yydef   f_def           
-#define        yychk   f_chk           
-#define        yypgo   f_pgo           
-#define        yyact   f_act           
-#define        yyexca  f_exca
-#define yyerrflag f_errflag
-#define yynerrs        f_nerrs
-#define        yyps    f_ps
-#define        yypv    f_pv
-#define        yys     f_s
-#define        yy_yys  f_yys
-#define        yystate f_state
-#define        yytmp   f_tmp
-#define        yyv     f_v
-#define        yy_yyv  f_yyv
-#define        yyval   f_val
-#define        yylloc  f_lloc
-#define yyreds f_reds          /* With YYDEBUG defined */
-#define yytoks f_toks          /* With YYDEBUG defined */
-#define yyname f_name          /* With YYDEBUG defined */
-#define yyrule f_rule          /* With YYDEBUG defined */
-#define yylhs  f_yylhs
-#define yylen  f_yylen
-#define yydefred f_yydefred
-#define yydgoto        f_yydgoto
-#define yysindex f_yysindex
-#define yyrindex f_yyrindex
-#define yygindex f_yygindex
-#define yytable         f_yytable
-#define yycheck         f_yycheck
-#define yyss   f_yyss
-#define yysslim        f_yysslim
-#define yyssp  f_yyssp
-#define yystacksize f_yystacksize
-#define yyvs   f_yyvs
-#define yyvsp  f_yyvsp
-
-#ifndef YYDEBUG
-#define        YYDEBUG 1               /* Default to yydebug support */
-#endif
-
-#define YYFPRINTF parser_fprintf
+#define parse_type(ps) builtin_type (ps->gdbarch ())
+#define parse_f_type(ps) builtin_f_type (ps->gdbarch ())
+
+/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
+   etc).  */
+#define GDB_YY_REMAP_PREFIX f_
+#include "yy-remap.h"
 
 /* The state of the parser, used internally when we are parsing the
    expression.  */
 
 static struct parser_state *pstate = NULL;
 
+/* Depth of parentheses.  */
+static int paren_depth;
+
+/* The current type stack.  */
+static struct type_stack *type_stack;
+
 int yyparse (void);
 
 static int yylex (void);
 
-void yyerror (char *);
+static void yyerror (const char *);
 
 static void growbuf_by_size (int);
 
 static int match_string_literal (void);
 
+static void push_kind_type (LONGEST val, struct type *type);
+
+static struct type *convert_to_kind_type (struct type *basetype, int kind);
+
+using namespace expr;
 %}
 
 /* Although the yacc "value" of an expression is not used,
@@ -145,14 +104,16 @@ static int match_string_literal (void);
       LONGEST val;
       struct type *type;
     } typed_val;
-    DOUBLEST dval;
+    struct {
+      gdb_byte val[16];
+      struct type *type;
+    } typed_val_float;
     struct symbol *sym;
     struct type *tval;
     struct stoken sval;
     struct ttype tsym;
     struct symtoken ssym;
     int voidval;
-    struct block *bval;
     enum exp_opcode opcode;
     struct internalvar *ivar;
 
@@ -176,7 +137,7 @@ static int parse_number (struct parser_state *, const char *, int,
 %type <tval> ptype
 
 %token <typed_val> INT
-%token <dval> FLOAT
+%token <typed_val_float> FLOAT
 
 /* Both NAME and TYPENAME tokens represent symbols in the input,
    and both convey their data as strings.
@@ -190,6 +151,7 @@ static int parse_number (struct parser_state *, const char *, int,
 %token <lval> BOOLEAN_LITERAL
 %token <ssym> NAME 
 %token <tsym> TYPENAME
+%token <voidval> COMPLETE
 %type <sval> name
 %type <ssym> name_not_typename
 
@@ -200,7 +162,7 @@ static int parse_number (struct parser_state *, const char *, int,
 
 %token <ssym> NAME_OR_INT 
 
-%token  SIZEOF 
+%token SIZEOF KIND
 %token ERROR
 
 /* Special type cases, put in to allow the parser to distinguish different
@@ -208,13 +170,17 @@ static int parse_number (struct parser_state *, const char *, int,
 %token INT_KEYWORD INT_S2_KEYWORD LOGICAL_S1_KEYWORD LOGICAL_S2_KEYWORD 
 %token LOGICAL_S8_KEYWORD
 %token LOGICAL_KEYWORD REAL_KEYWORD REAL_S8_KEYWORD REAL_S16_KEYWORD 
+%token COMPLEX_KEYWORD
 %token COMPLEX_S8_KEYWORD COMPLEX_S16_KEYWORD COMPLEX_S32_KEYWORD 
 %token BOOL_AND BOOL_OR BOOL_NOT   
+%token SINGLE DOUBLE PRECISION
 %token <lval> CHARACTER 
 
-%token <voidval> VARIABLE
+%token <sval> DOLLAR_VARIABLE
 
 %token <opcode> ASSIGN_MODIFY
+%token <opcode> UNOP_INTRINSIC BINOP_INTRINSIC
+%token <opcode> UNOP_OR_BINOP_INTRINSIC
 
 %left ','
 %left ABOVE_COMMA
@@ -245,38 +211,88 @@ start   : exp
        ;
 
 type_exp:      type
-                       { write_exp_elt_opcode (pstate, OP_TYPE);
-                         write_exp_elt_type (pstate, $1);
-                         write_exp_elt_opcode (pstate, OP_TYPE); }
+                       { pstate->push_new<type_operation> ($1); }
        ;
 
 exp     :       '(' exp ')'
-                       { }
-        ;
+                       { }
+       ;
 
 /* Expressions, not including the comma operator.  */
 exp    :       '*' exp    %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_IND); }
+                       { pstate->wrap<unop_ind_operation> (); }
        ;
 
 exp    :       '&' exp    %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_ADDR); }
+                       { pstate->wrap<unop_addr_operation> (); }
        ;
 
 exp    :       '-' exp    %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_NEG); }
+                       { pstate->wrap<unary_neg_operation> (); }
        ;
 
 exp    :       BOOL_NOT exp    %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_LOGICAL_NOT); }
+                       { pstate->wrap<unary_logical_not_operation> (); }
        ;
 
 exp    :       '~' exp    %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_COMPLEMENT); }
+                       { pstate->wrap<unary_complement_operation> (); }
        ;
 
 exp    :       SIZEOF exp       %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_SIZEOF); }
+                       { pstate->wrap<unop_sizeof_operation> (); }
+       ;
+
+exp    :       KIND '(' exp ')'       %prec UNARY
+                       { pstate->wrap<fortran_kind_operation> (); }
+       ;
+
+exp    :       UNOP_OR_BINOP_INTRINSIC '('
+                       { pstate->start_arglist (); }
+               one_or_two_args ')'
+                       {
+                         int n = pstate->end_arglist ();
+                         gdb_assert (n == 1 || n == 2);
+                         if ($1 == FORTRAN_ASSOCIATED)
+                           {
+                             if (n == 1)
+                               pstate->wrap<fortran_associated_1arg> ();
+                             else
+                               pstate->wrap2<fortran_associated_2arg> ();
+                           }
+                         else if ($1 == FORTRAN_ARRAY_SIZE)
+                           {
+                             if (n == 1)
+                               pstate->wrap<fortran_array_size_1arg> ();
+                             else
+                               pstate->wrap2<fortran_array_size_2arg> ();
+                           }
+                         else
+                           {
+                             std::vector<operation_up> args
+                               = pstate->pop_vector (n);
+                             gdb_assert ($1 == FORTRAN_LBOUND
+                                         || $1 == FORTRAN_UBOUND);
+                             operation_up op;
+                             if (n == 1)
+                               op.reset
+                                 (new fortran_bound_1arg ($1,
+                                                          std::move (args[0])));
+                             else
+                               op.reset
+                                 (new fortran_bound_2arg ($1,
+                                                          std::move (args[0]),
+                                                          std::move (args[1])));
+                             pstate->push (std::move (op));
+                           }
+                       }
+       ;
+
+one_or_two_args
+       :       exp
+                       { pstate->arglist_len = 1; }
+       |       exp ',' exp
+                       { pstate->arglist_len = 2; }
        ;
 
 /* No more explicit array operators, we treat everything in F77 as 
@@ -285,271 +301,377 @@ exp     :       SIZEOF exp       %prec UNARY
    later in eval.c.  */
 
 exp    :       exp '(' 
-                       { start_arglist (); }
+                       { pstate->start_arglist (); }
                arglist ')'     
-                       { write_exp_elt_opcode (pstate,
-                                               OP_F77_UNDETERMINED_ARGLIST);
-                         write_exp_elt_longcst (pstate,
-                                                (LONGEST) end_arglist ());
-                         write_exp_elt_opcode (pstate,
-                                             OP_F77_UNDETERMINED_ARGLIST); }
+                       {
+                         std::vector<operation_up> args
+                           = pstate->pop_vector (pstate->end_arglist ());
+                         pstate->push_new<fortran_undetermined>
+                           (pstate->pop (), std::move (args));
+                       }
+       ;
+
+exp    :       UNOP_INTRINSIC '(' exp ')'
+                       {
+                         switch ($1)
+                           {
+                           case UNOP_ABS:
+                             pstate->wrap<fortran_abs_operation> ();
+                             break;
+                           case UNOP_FORTRAN_FLOOR:
+                             pstate->wrap<fortran_floor_operation> ();
+                             break;
+                           case UNOP_FORTRAN_CEILING:
+                             pstate->wrap<fortran_ceil_operation> ();
+                             break;
+                           case UNOP_FORTRAN_ALLOCATED:
+                             pstate->wrap<fortran_allocated_operation> ();
+                             break;
+                           case UNOP_FORTRAN_RANK:
+                             pstate->wrap<fortran_rank_operation> ();
+                             break;
+                           case UNOP_FORTRAN_SHAPE:
+                             pstate->wrap<fortran_array_shape_operation> ();
+                             break;
+                           case UNOP_FORTRAN_LOC:
+                             pstate->wrap<fortran_loc_operation> ();
+                             break;
+                           default:
+                             gdb_assert_not_reached ("unhandled intrinsic");
+                           }
+                       }
+       ;
+
+exp    :       BINOP_INTRINSIC '(' exp ',' exp ')'
+                       {
+                         switch ($1)
+                           {
+                           case BINOP_MOD:
+                             pstate->wrap2<fortran_mod_operation> ();
+                             break;
+                           case BINOP_FORTRAN_MODULO:
+                             pstate->wrap2<fortran_modulo_operation> ();
+                             break;
+                           case BINOP_FORTRAN_CMPLX:
+                             pstate->wrap2<fortran_cmplx_operation> ();
+                             break;
+                           default:
+                             gdb_assert_not_reached ("unhandled intrinsic");
+                           }
+                       }
        ;
 
 arglist        :
        ;
 
 arglist        :       exp
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
 
 arglist :      subrange
-                       { arglist_len = 1; }
+                       { pstate->arglist_len = 1; }
        ;
    
 arglist        :       arglist ',' exp   %prec ABOVE_COMMA
-                       { arglist_len++; }
+                       { pstate->arglist_len++; }
+       ;
+
+arglist        :       arglist ',' subrange   %prec ABOVE_COMMA
+                       { pstate->arglist_len++; }
        ;
 
 /* There are four sorts of subrange types in F90.  */
 
 subrange:      exp ':' exp     %prec ABOVE_COMMA
-                       { write_exp_elt_opcode (pstate, OP_F90_RANGE); 
-                         write_exp_elt_longcst (pstate, NONE_BOUND_DEFAULT);
-                         write_exp_elt_opcode (pstate, OP_F90_RANGE); }
+                       {
+                         operation_up high = pstate->pop ();
+                         operation_up low = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_STANDARD, std::move (low),
+                            std::move (high), operation_up ());
+                       }
        ;
 
 subrange:      exp ':' %prec ABOVE_COMMA
-                       { write_exp_elt_opcode (pstate, OP_F90_RANGE);
-                         write_exp_elt_longcst (pstate, HIGH_BOUND_DEFAULT);
-                         write_exp_elt_opcode (pstate, OP_F90_RANGE); }
+                       {
+                         operation_up low = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_HIGH_BOUND_DEFAULT, std::move (low),
+                            operation_up (), operation_up ());
+                       }
        ;
 
 subrange:      ':' exp %prec ABOVE_COMMA
-                       { write_exp_elt_opcode (pstate, OP_F90_RANGE);
-                         write_exp_elt_longcst (pstate, LOW_BOUND_DEFAULT);
-                         write_exp_elt_opcode (pstate, OP_F90_RANGE); }
+                       {
+                         operation_up high = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_LOW_BOUND_DEFAULT, operation_up (),
+                            std::move (high), operation_up ());
+                       }
        ;
 
 subrange:      ':'     %prec ABOVE_COMMA
-                       { write_exp_elt_opcode (pstate, OP_F90_RANGE);
-                         write_exp_elt_longcst (pstate, BOTH_BOUND_DEFAULT);
-                         write_exp_elt_opcode (pstate, OP_F90_RANGE); }
+                       {
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_LOW_BOUND_DEFAULT
+                            | RANGE_HIGH_BOUND_DEFAULT,
+                            operation_up (), operation_up (),
+                            operation_up ());
+                       }
+       ;
+
+/* And each of the four subrange types can also have a stride.  */
+subrange:      exp ':' exp ':' exp     %prec ABOVE_COMMA
+                       {
+                         operation_up stride = pstate->pop ();
+                         operation_up high = pstate->pop ();
+                         operation_up low = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_STANDARD | RANGE_HAS_STRIDE,
+                            std::move (low), std::move (high),
+                            std::move (stride));
+                       }
+       ;
+
+subrange:      exp ':' ':' exp %prec ABOVE_COMMA
+                       {
+                         operation_up stride = pstate->pop ();
+                         operation_up low = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_HIGH_BOUND_DEFAULT
+                            | RANGE_HAS_STRIDE,
+                            std::move (low), operation_up (),
+                            std::move (stride));
+                       }
+       ;
+
+subrange:      ':' exp ':' exp %prec ABOVE_COMMA
+                       {
+                         operation_up stride = pstate->pop ();
+                         operation_up high = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_LOW_BOUND_DEFAULT
+                            | RANGE_HAS_STRIDE,
+                            operation_up (), std::move (high),
+                            std::move (stride));
+                       }
+       ;
+
+subrange:      ':' ':' exp     %prec ABOVE_COMMA
+                       {
+                         operation_up stride = pstate->pop ();
+                         pstate->push_new<fortran_range_operation>
+                           (RANGE_LOW_BOUND_DEFAULT
+                            | RANGE_HIGH_BOUND_DEFAULT
+                            | RANGE_HAS_STRIDE,
+                            operation_up (), operation_up (),
+                            std::move (stride));
+                       }
        ;
 
 complexnum:     exp ',' exp 
-                       { }                          
-        ;
+                       { }                          
+       ;
 
 exp    :       '(' complexnum ')'
-                       { write_exp_elt_opcode (pstate, OP_COMPLEX);
-                         write_exp_elt_type (pstate,
-                                             parse_f_type (pstate)
-                                             ->builtin_complex_s16);
-                         write_exp_elt_opcode (pstate, OP_COMPLEX); }
+                       {
+                         operation_up rhs = pstate->pop ();
+                         operation_up lhs = pstate->pop ();
+                         pstate->push_new<complex_operation>
+                           (std::move (lhs), std::move (rhs),
+                            parse_f_type (pstate)->builtin_complex_s16);
+                       }
        ;
 
 exp    :       '(' type ')' exp  %prec UNARY
-                       { write_exp_elt_opcode (pstate, UNOP_CAST);
-                         write_exp_elt_type (pstate, $2);
-                         write_exp_elt_opcode (pstate, UNOP_CAST); }
+                       {
+                         pstate->push_new<unop_cast_operation>
+                           (pstate->pop (), $2);
+                       }
        ;
 
 exp     :       exp '%' name
-                        { write_exp_elt_opcode (pstate, STRUCTOP_STRUCT);
-                          write_exp_string (pstate, $3);
-                          write_exp_elt_opcode (pstate, STRUCTOP_STRUCT); }
-        ;
+                       {
+                         pstate->push_new<fortran_structop_operation>
+                           (pstate->pop (), copy_name ($3));
+                       }
+       ;
+
+exp     :       exp '%' name COMPLETE
+                       {
+                         structop_base_operation *op
+                           = new fortran_structop_operation (pstate->pop (),
+                                                             copy_name ($3));
+                         pstate->mark_struct_expression (op);
+                         pstate->push (operation_up (op));
+                       }
+       ;
+
+exp     :       exp '%' COMPLETE
+                       {
+                         structop_base_operation *op
+                           = new fortran_structop_operation (pstate->pop (),
+                                                             "");
+                         pstate->mark_struct_expression (op);
+                         pstate->push (operation_up (op));
+                       }
+       ;
 
 /* Binary operators in order of decreasing precedence.  */
 
 exp    :       exp '@' exp
-                       { write_exp_elt_opcode (pstate, BINOP_REPEAT); }
+                       { pstate->wrap2<repeat_operation> (); }
        ;
 
 exp    :       exp STARSTAR exp
-                       { write_exp_elt_opcode (pstate, BINOP_EXP); }
+                       { pstate->wrap2<exp_operation> (); }
        ;
 
 exp    :       exp '*' exp
-                       { write_exp_elt_opcode (pstate, BINOP_MUL); }
+                       { pstate->wrap2<mul_operation> (); }
        ;
 
 exp    :       exp '/' exp
-                       { write_exp_elt_opcode (pstate, BINOP_DIV); }
+                       { pstate->wrap2<div_operation> (); }
        ;
 
 exp    :       exp '+' exp
-                       { write_exp_elt_opcode (pstate, BINOP_ADD); }
+                       { pstate->wrap2<add_operation> (); }
        ;
 
 exp    :       exp '-' exp
-                       { write_exp_elt_opcode (pstate, BINOP_SUB); }
+                       { pstate->wrap2<sub_operation> (); }
        ;
 
 exp    :       exp LSH exp
-                       { write_exp_elt_opcode (pstate, BINOP_LSH); }
+                       { pstate->wrap2<lsh_operation> (); }
        ;
 
 exp    :       exp RSH exp
-                       { write_exp_elt_opcode (pstate, BINOP_RSH); }
+                       { pstate->wrap2<rsh_operation> (); }
        ;
 
 exp    :       exp EQUAL exp
-                       { write_exp_elt_opcode (pstate, BINOP_EQUAL); }
+                       { pstate->wrap2<equal_operation> (); }
        ;
 
 exp    :       exp NOTEQUAL exp
-                       { write_exp_elt_opcode (pstate, BINOP_NOTEQUAL); }
+                       { pstate->wrap2<notequal_operation> (); }
        ;
 
 exp    :       exp LEQ exp
-                       { write_exp_elt_opcode (pstate, BINOP_LEQ); }
+                       { pstate->wrap2<leq_operation> (); }
        ;
 
 exp    :       exp GEQ exp
-                       { write_exp_elt_opcode (pstate, BINOP_GEQ); }
+                       { pstate->wrap2<geq_operation> (); }
        ;
 
 exp    :       exp LESSTHAN exp
-                       { write_exp_elt_opcode (pstate, BINOP_LESS); }
+                       { pstate->wrap2<less_operation> (); }
        ;
 
 exp    :       exp GREATERTHAN exp
-                       { write_exp_elt_opcode (pstate, BINOP_GTR); }
+                       { pstate->wrap2<gtr_operation> (); }
        ;
 
 exp    :       exp '&' exp
-                       { write_exp_elt_opcode (pstate, BINOP_BITWISE_AND); }
+                       { pstate->wrap2<bitwise_and_operation> (); }
        ;
 
 exp    :       exp '^' exp
-                       { write_exp_elt_opcode (pstate, BINOP_BITWISE_XOR); }
+                       { pstate->wrap2<bitwise_xor_operation> (); }
        ;
 
 exp    :       exp '|' exp
-                       { write_exp_elt_opcode (pstate, BINOP_BITWISE_IOR); }
+                       { pstate->wrap2<bitwise_ior_operation> (); }
        ;
 
 exp     :       exp BOOL_AND exp
-                       { write_exp_elt_opcode (pstate, BINOP_LOGICAL_AND); }
+                       { pstate->wrap2<logical_and_operation> (); }
        ;
 
 
 exp    :       exp BOOL_OR exp
-                       { write_exp_elt_opcode (pstate, BINOP_LOGICAL_OR); }
+                       { pstate->wrap2<logical_or_operation> (); }
        ;
 
 exp    :       exp '=' exp
-                       { write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
+                       { pstate->wrap2<assign_operation> (); }
        ;
 
 exp    :       exp ASSIGN_MODIFY exp
-                       { write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY);
-                         write_exp_elt_opcode (pstate, $2);
-                         write_exp_elt_opcode (pstate, BINOP_ASSIGN_MODIFY); }
+                       {
+                         operation_up rhs = pstate->pop ();
+                         operation_up lhs = pstate->pop ();
+                         pstate->push_new<assign_modify_operation>
+                           ($2, std::move (lhs), std::move (rhs));
+                       }
        ;
 
 exp    :       INT
-                       { write_exp_elt_opcode (pstate, OP_LONG);
-                         write_exp_elt_type (pstate, $1.type);
-                         write_exp_elt_longcst (pstate, (LONGEST) ($1.val));
-                         write_exp_elt_opcode (pstate, OP_LONG); }
+                       {
+                         pstate->push_new<long_const_operation>
+                           ($1.type, $1.val);
+                       }
        ;
 
 exp    :       NAME_OR_INT
                        { YYSTYPE val;
                          parse_number (pstate, $1.stoken.ptr,
                                        $1.stoken.length, 0, &val);
-                         write_exp_elt_opcode (pstate, OP_LONG);
-                         write_exp_elt_type (pstate, val.typed_val.type);
-                         write_exp_elt_longcst (pstate,
-                                                (LONGEST)val.typed_val.val);
-                         write_exp_elt_opcode (pstate, OP_LONG); }
+                         pstate->push_new<long_const_operation>
+                           (val.typed_val.type,
+                            val.typed_val.val);
+                       }
        ;
 
 exp    :       FLOAT
-                       { write_exp_elt_opcode (pstate, OP_DOUBLE);
-                         write_exp_elt_type (pstate,
-                                             parse_f_type (pstate)
-                                             ->builtin_real_s8);
-                         write_exp_elt_dblcst (pstate, $1);
-                         write_exp_elt_opcode (pstate, OP_DOUBLE); }
+                       {
+                         float_data data;
+                         std::copy (std::begin ($1.val), std::end ($1.val),
+                                    std::begin (data));
+                         pstate->push_new<float_const_operation> ($1.type, data);
+                       }
        ;
 
 exp    :       variable
        ;
 
-exp    :       VARIABLE
+exp    :       DOLLAR_VARIABLE
+                       { pstate->push_dollar ($1); }
        ;
 
 exp    :       SIZEOF '(' type ')'     %prec UNARY
-                       { write_exp_elt_opcode (pstate, OP_LONG);
-                         write_exp_elt_type (pstate,
-                                             parse_f_type (pstate)
-                                             ->builtin_integer);
-                         CHECK_TYPEDEF ($3);
-                         write_exp_elt_longcst (pstate,
-                                                (LONGEST) TYPE_LENGTH ($3));
-                         write_exp_elt_opcode (pstate, OP_LONG); }
+                       {
+                         $3 = check_typedef ($3);
+                         pstate->push_new<long_const_operation>
+                           (parse_f_type (pstate)->builtin_integer,
+                            TYPE_LENGTH ($3));
+                       }
        ;
 
 exp     :       BOOLEAN_LITERAL
-                       { write_exp_elt_opcode (pstate, OP_BOOL);
-                         write_exp_elt_longcst (pstate, (LONGEST) $1);
-                         write_exp_elt_opcode (pstate, OP_BOOL);
-                       }
-        ;
+                       { pstate->push_new<bool_operation> ($1); }
+       ;
 
 exp    :       STRING_LITERAL
                        {
-                         write_exp_elt_opcode (pstate, OP_STRING);
-                         write_exp_string (pstate, $1);
-                         write_exp_elt_opcode (pstate, OP_STRING);
+                         pstate->push_new<string_operation>
+                           (copy_name ($1));
                        }
        ;
 
 variable:      name_not_typename
-                       { struct symbol *sym = $1.sym;
-
-                         if (sym)
-                           {
-                             if (symbol_read_needs_frame (sym))
-                               {
-                                 if (innermost_block == 0
-                                     || contained_in (block_found, 
-                                                      innermost_block))
-                                   innermost_block = block_found;
-                               }
-                             write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                             /* We want to use the selected frame, not
-                                another more inner frame which happens to
-                                be in the same block.  */
-                             write_exp_elt_block (pstate, NULL);
-                             write_exp_elt_sym (pstate, sym);
-                             write_exp_elt_opcode (pstate, OP_VAR_VALUE);
-                             break;
-                           }
-                         else
-                           {
-                             struct bound_minimal_symbol msymbol;
-                             char *arg = copy_name ($1.stoken);
-
-                             msymbol =
-                               lookup_bound_minimal_symbol (arg);
-                             if (msymbol.minsym != NULL)
-                               write_exp_msymbol (pstate, msymbol);
-                             else if (!have_full_symbols () && !have_partial_symbols ())
-                               error (_("No symbol table is loaded.  Use the \"file\" command."));
-                             else
-                               error (_("No symbol \"%s\" in current context."),
-                                      copy_name ($1.stoken));
-                           }
+                       { struct block_symbol sym = $1.sym;
+                         std::string name = copy_name ($1.stoken);
+                         pstate->push_symbol (name.c_str (), sym);
                        }
        ;
 
 
 type    :       ptype
-        ;
+       ;
 
 ptype  :       typebase
        |       typebase abs_decl
@@ -561,7 +683,7 @@ ptype       :       typebase
                  struct type *range_type;
                  
                  while (!done)
-                   switch (pop_type ())
+                   switch (type_stack->pop ())
                      {
                      case tp_end:
                        done = 1;
@@ -570,10 +692,10 @@ ptype     :       typebase
                        follow_type = lookup_pointer_type (follow_type);
                        break;
                      case tp_reference:
-                       follow_type = lookup_reference_type (follow_type);
+                       follow_type = lookup_lvalue_reference_type (follow_type);
                        break;
                      case tp_array:
-                       array_size = pop_type_int ();
+                       array_size = type_stack->pop_int ();
                        if (array_size != -1)
                          {
                            range_type =
@@ -591,28 +713,39 @@ ptype     :       typebase
                      case tp_function:
                        follow_type = lookup_function_type (follow_type);
                        break;
+                     case tp_kind:
+                       {
+                         int kind_val = type_stack->pop_int ();
+                         follow_type
+                           = convert_to_kind_type (follow_type, kind_val);
+                       }
+                       break;
                      }
                  $$ = follow_type;
                }
        ;
 
 abs_decl:      '*'
-                       { push_type (tp_pointer); $$ = 0; }
+                       { type_stack->push (tp_pointer); $$ = 0; }
        |       '*' abs_decl
-                       { push_type (tp_pointer); $$ = $2; }
+                       { type_stack->push (tp_pointer); $$ = $2; }
        |       '&'
-                       { push_type (tp_reference); $$ = 0; }
+                       { type_stack->push (tp_reference); $$ = 0; }
        |       '&' abs_decl
-                       { push_type (tp_reference); $$ = $2; }
+                       { type_stack->push (tp_reference); $$ = $2; }
        |       direct_abs_decl
        ;
 
 direct_abs_decl: '(' abs_decl ')'
                        { $$ = $2; }
+       |       '(' KIND '=' INT ')'
+                       { push_kind_type ($4.val, $4.type); }
+       |       '*' INT
+                       { push_kind_type ($2.val, $2.type); }
        |       direct_abs_decl func_mod
-                       { push_type (tp_function); }
+                       { type_stack->push (tp_function); }
        |       func_mod
-                       { push_type (tp_function); }
+                       { type_stack->push (tp_function); }
        ;
 
 func_mod:      '(' ')'
@@ -644,12 +777,22 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
                        { $$ = parse_f_type (pstate)->builtin_real_s8; }
        |       REAL_S16_KEYWORD
                        { $$ = parse_f_type (pstate)->builtin_real_s16; }
+       |       COMPLEX_KEYWORD
+                       { $$ = parse_f_type (pstate)->builtin_complex_s8; }
        |       COMPLEX_S8_KEYWORD
                        { $$ = parse_f_type (pstate)->builtin_complex_s8; }
        |       COMPLEX_S16_KEYWORD 
                        { $$ = parse_f_type (pstate)->builtin_complex_s16; }
        |       COMPLEX_S32_KEYWORD 
                        { $$ = parse_f_type (pstate)->builtin_complex_s32; }
+       |       SINGLE PRECISION
+                       { $$ = parse_f_type (pstate)->builtin_real;}
+       |       DOUBLE PRECISION
+                       { $$ = parse_f_type (pstate)->builtin_real_s8;}
+       |       SINGLE COMPLEX_KEYWORD
+                       { $$ = parse_f_type (pstate)->builtin_complex_s8;}
+       |       DOUBLE COMPLEX_KEYWORD
+                       { $$ = parse_f_type (pstate)->builtin_complex_s16;}
        ;
 
 nonempty_typelist
@@ -704,16 +847,22 @@ parse_number (struct parser_state *par_state,
   if (parsed_float)
     {
       /* It's a float since it contains a point or an exponent.  */
-      /* [dD] is not understood as an exponent by atof, change it to 'e'.  */
+      /* [dD] is not understood as an exponent by parse_float,
+        change it to 'e'.  */
       char *tmp, *tmp2;
 
       tmp = xstrdup (p);
       for (tmp2 = tmp; *tmp2; ++tmp2)
        if (*tmp2 == 'd' || *tmp2 == 'D')
          *tmp2 = 'e';
-      putithere->dval = atof (tmp);
+
+      /* FIXME: Should this use different types?  */
+      putithere->typed_val_float.type = parse_f_type (pstate)->builtin_real_s8;
+      bool parsed = parse_float (tmp, len,
+                                putithere->typed_val_float.type,
+                                putithere->typed_val_float.val);
       free (tmp);
-      return FLOAT;
+      return parsed? FLOAT : ERROR;
     }
 
   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
@@ -795,22 +944,22 @@ parse_number (struct parser_state *par_state,
      are the same size.  So we shift it twice, with fewer bits
      each time, for the same result.  */
   
-  if ((gdbarch_int_bit (parse_gdbarch (par_state))
-       != gdbarch_long_bit (parse_gdbarch (par_state))
+  if ((gdbarch_int_bit (par_state->gdbarch ())
+       != gdbarch_long_bit (par_state->gdbarch ())
        && ((n >> 2)
-          >> (gdbarch_int_bit (parse_gdbarch (par_state))-2))) /* Avoid
+          >> (gdbarch_int_bit (par_state->gdbarch ())-2))) /* Avoid
                                                            shift warning */
       || long_p)
     {
       high_bit = ((ULONGEST)1)
-      << (gdbarch_long_bit (parse_gdbarch (par_state))-1);
+      << (gdbarch_long_bit (par_state->gdbarch ())-1);
       unsigned_type = parse_type (par_state)->builtin_unsigned_long;
       signed_type = parse_type (par_state)->builtin_long;
     }
   else 
     {
       high_bit =
-       ((ULONGEST)1) << (gdbarch_int_bit (parse_gdbarch (par_state)) - 1);
+       ((ULONGEST)1) << (gdbarch_int_bit (par_state->gdbarch ()) - 1);
       unsigned_type = parse_type (par_state)->builtin_unsigned_int;
       signed_type = parse_type (par_state)->builtin_int;
     }    
@@ -828,74 +977,190 @@ parse_number (struct parser_state *par_state,
   return INT;
 }
 
+/* Called to setup the type stack when we encounter a '(kind=N)' type
+   modifier, performs some bounds checking on 'N' and then pushes this to
+   the type stack followed by the 'tp_kind' marker.  */
+static void
+push_kind_type (LONGEST val, struct type *type)
+{
+  int ival;
+
+  if (type->is_unsigned ())
+    {
+      ULONGEST uval = static_cast <ULONGEST> (val);
+      if (uval > INT_MAX)
+       error (_("kind value out of range"));
+      ival = static_cast <int> (uval);
+    }
+  else
+    {
+      if (val > INT_MAX || val < 0)
+       error (_("kind value out of range"));
+      ival = static_cast <int> (val);
+    }
+
+  type_stack->push (ival);
+  type_stack->push (tp_kind);
+}
+
+/* Called when a type has a '(kind=N)' modifier after it, for example
+   'character(kind=1)'.  The BASETYPE is the type described by 'character'
+   in our example, and KIND is the integer '1'.  This function returns a
+   new type that represents the basetype of a specific kind.  */
+static struct type *
+convert_to_kind_type (struct type *basetype, int kind)
+{
+  if (basetype == parse_f_type (pstate)->builtin_character)
+    {
+      /* Character of kind 1 is a special case, this is the same as the
+        base character type.  */
+      if (kind == 1)
+       return parse_f_type (pstate)->builtin_character;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_complex_s8)
+    {
+      if (kind == 4)
+       return parse_f_type (pstate)->builtin_complex_s8;
+      else if (kind == 8)
+       return parse_f_type (pstate)->builtin_complex_s16;
+      else if (kind == 16)
+       return parse_f_type (pstate)->builtin_complex_s32;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_real)
+    {
+      if (kind == 4)
+       return parse_f_type (pstate)->builtin_real;
+      else if (kind == 8)
+       return parse_f_type (pstate)->builtin_real_s8;
+      else if (kind == 16)
+       return parse_f_type (pstate)->builtin_real_s16;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_logical)
+    {
+      if (kind == 1)
+       return parse_f_type (pstate)->builtin_logical_s1;
+      else if (kind == 2)
+       return parse_f_type (pstate)->builtin_logical_s2;
+      else if (kind == 4)
+       return parse_f_type (pstate)->builtin_logical;
+      else if (kind == 8)
+       return parse_f_type (pstate)->builtin_logical_s8;
+    }
+  else if (basetype == parse_f_type (pstate)->builtin_integer)
+    {
+      if (kind == 2)
+       return parse_f_type (pstate)->builtin_integer_s2;
+      else if (kind == 4)
+       return parse_f_type (pstate)->builtin_integer;
+      else if (kind == 8)
+       return parse_f_type (pstate)->builtin_integer_s8;
+    }
+
+  error (_("unsupported kind %d for type %s"),
+        kind, TYPE_SAFE_NAME (basetype));
+
+  /* Should never get here.  */
+  return nullptr;
+}
+
 struct token
 {
-  char *operator;
+  /* The string to match against.  */
+  const char *oper;
+
+  /* The lexer token to return.  */
   int token;
+
+  /* The expression opcode to embed within the token.  */
   enum exp_opcode opcode;
+
+  /* When this is true the string in OPER is matched exactly including
+     case, when this is false OPER is matched case insensitively.  */
+  bool case_sensitive;
 };
 
-static const struct token dot_ops[] =
+/* List of Fortran operators.  */
+
+static const struct token fortran_operators[] =
 {
-  { ".and.", BOOL_AND, BINOP_END },
-  { ".AND.", BOOL_AND, BINOP_END },
-  { ".or.", BOOL_OR, BINOP_END },
-  { ".OR.", BOOL_OR, BINOP_END },
-  { ".not.", BOOL_NOT, BINOP_END },
-  { ".NOT.", BOOL_NOT, BINOP_END },
-  { ".eq.", EQUAL, BINOP_END },
-  { ".EQ.", EQUAL, BINOP_END },
-  { ".eqv.", EQUAL, BINOP_END },
-  { ".NEQV.", NOTEQUAL, BINOP_END },
-  { ".neqv.", NOTEQUAL, BINOP_END },
-  { ".EQV.", EQUAL, BINOP_END },
-  { ".ne.", NOTEQUAL, BINOP_END },
-  { ".NE.", NOTEQUAL, BINOP_END },
-  { ".le.", LEQ, BINOP_END },
-  { ".LE.", LEQ, BINOP_END },
-  { ".ge.", GEQ, BINOP_END },
-  { ".GE.", GEQ, BINOP_END },
-  { ".gt.", GREATERTHAN, BINOP_END },
-  { ".GT.", GREATERTHAN, BINOP_END },
-  { ".lt.", LESSTHAN, BINOP_END },
-  { ".LT.", LESSTHAN, BINOP_END },
-  { NULL, 0, 0 }
+  { ".and.", BOOL_AND, OP_NULL, false },
+  { ".or.", BOOL_OR, OP_NULL, false },
+  { ".not.", BOOL_NOT, OP_NULL, false },
+  { ".eq.", EQUAL, OP_NULL, false },
+  { ".eqv.", EQUAL, OP_NULL, false },
+  { ".neqv.", NOTEQUAL, OP_NULL, false },
+  { ".xor.", NOTEQUAL, OP_NULL, false },
+  { "==", EQUAL, OP_NULL, false },
+  { ".ne.", NOTEQUAL, OP_NULL, false },
+  { "/=", NOTEQUAL, OP_NULL, false },
+  { ".le.", LEQ, OP_NULL, false },
+  { "<=", LEQ, OP_NULL, false },
+  { ".ge.", GEQ, OP_NULL, false },
+  { ">=", GEQ, OP_NULL, false },
+  { ".gt.", GREATERTHAN, OP_NULL, false },
+  { ">", GREATERTHAN, OP_NULL, false },
+  { ".lt.", LESSTHAN, OP_NULL, false },
+  { "<", LESSTHAN, OP_NULL, false },
+  { "**", STARSTAR, BINOP_EXP, false },
 };
 
-struct f77_boolean_val 
+/* Holds the Fortran representation of a boolean, and the integer value we
+   substitute in when one of the matching strings is parsed.  */
+struct f77_boolean_val
 {
-  char *name;
+  /* The string representing a Fortran boolean.  */
+  const char *name;
+
+  /* The integer value to replace it with.  */
   int value;
-}; 
+};
 
-static const struct f77_boolean_val boolean_values[]  = 
+/* The set of Fortran booleans.  These are matched case insensitively.  */
+static const struct f77_boolean_val boolean_values[]  =
 {
   { ".true.", 1 },
-  { ".TRUE.", 1 },
-  { ".false.", 0 },
-  { ".FALSE.", 0 },
-  { NULL, 0 }
+  { ".false.", 0 }
 };
 
-static const struct token f77_keywords[] = 
+static const struct token f77_keywords[] =
 {
-  { "complex_16", COMPLEX_S16_KEYWORD, BINOP_END },
-  { "complex_32", COMPLEX_S32_KEYWORD, BINOP_END },
-  { "character", CHARACTER, BINOP_END },
-  { "integer_2", INT_S2_KEYWORD, BINOP_END },
-  { "logical_1", LOGICAL_S1_KEYWORD, BINOP_END },
-  { "logical_2", LOGICAL_S2_KEYWORD, BINOP_END },
-  { "logical_8", LOGICAL_S8_KEYWORD, BINOP_END },
-  { "complex_8", COMPLEX_S8_KEYWORD, BINOP_END },
-  { "integer", INT_KEYWORD, BINOP_END },
-  { "logical", LOGICAL_KEYWORD, BINOP_END },
-  { "real_16", REAL_S16_KEYWORD, BINOP_END },
-  { "complex", COMPLEX_S8_KEYWORD, BINOP_END },
-  { "sizeof", SIZEOF, BINOP_END },
-  { "real_8", REAL_S8_KEYWORD, BINOP_END },
-  { "real", REAL_KEYWORD, BINOP_END },
-  { NULL, 0, 0 }
-}; 
+  /* Historically these have always been lowercase only in GDB.  */
+  { "complex_16", COMPLEX_S16_KEYWORD, OP_NULL, true },
+  { "complex_32", COMPLEX_S32_KEYWORD, OP_NULL, true },
+  { "character", CHARACTER, OP_NULL, true },
+  { "integer_2", INT_S2_KEYWORD, OP_NULL, true },
+  { "logical_1", LOGICAL_S1_KEYWORD, OP_NULL, true },
+  { "logical_2", LOGICAL_S2_KEYWORD, OP_NULL, true },
+  { "logical_8", LOGICAL_S8_KEYWORD, OP_NULL, true },
+  { "complex_8", COMPLEX_S8_KEYWORD, OP_NULL, true },
+  { "integer", INT_KEYWORD, OP_NULL, true },
+  { "logical", LOGICAL_KEYWORD, OP_NULL, true },
+  { "real_16", REAL_S16_KEYWORD, OP_NULL, true },
+  { "complex", COMPLEX_KEYWORD, OP_NULL, true },
+  { "sizeof", SIZEOF, OP_NULL, true },
+  { "real_8", REAL_S8_KEYWORD, OP_NULL, true },
+  { "real", REAL_KEYWORD, OP_NULL, true },
+  { "single", SINGLE, OP_NULL, true },
+  { "double", DOUBLE, OP_NULL, true },
+  { "precision", PRECISION, OP_NULL, true },
+  /* The following correspond to actual functions in Fortran and are case
+     insensitive.  */
+  { "kind", KIND, OP_NULL, false },
+  { "abs", UNOP_INTRINSIC, UNOP_ABS, false },
+  { "mod", BINOP_INTRINSIC, BINOP_MOD, false },
+  { "floor", UNOP_INTRINSIC, UNOP_FORTRAN_FLOOR, false },
+  { "ceiling", UNOP_INTRINSIC, UNOP_FORTRAN_CEILING, false },
+  { "modulo", BINOP_INTRINSIC, BINOP_FORTRAN_MODULO, false },
+  { "cmplx", BINOP_INTRINSIC, BINOP_FORTRAN_CMPLX, false },
+  { "lbound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_LBOUND, false },
+  { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
+  { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false },
+  { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false },
+  { "rank", UNOP_INTRINSIC, UNOP_FORTRAN_RANK, false },
+  { "size", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ARRAY_SIZE, false },
+  { "shape", UNOP_INTRINSIC, UNOP_FORTRAN_SHAPE, false },
+  { "loc", UNOP_INTRINSIC, UNOP_FORTRAN_LOC, false },
+};
 
 /* Implementation of a dynamically expandable buffer for processing input
    characters acquired through lexptr and building a value to return in
@@ -924,7 +1189,7 @@ growbuf_by_size (int count)
 {
   int growby;
 
-  growby = max (count, GROWBY_MIN_SIZE);
+  growby = std::max (count, GROWBY_MIN_SIZE);
   tempbufsize += growby;
   if (tempbuf == NULL)
     tempbuf = (char *) malloc (tempbufsize);
@@ -944,14 +1209,14 @@ growbuf_by_size (int count)
 static int
 match_string_literal (void)
 {
-  const char *tokptr = lexptr;
+  const char *tokptr = pstate->lexptr;
 
   for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
     {
       CHECKBUF (1);
-      if (*tokptr == *lexptr)
+      if (*tokptr == *pstate->lexptr)
        {
-         if (*(tokptr + 1) == *lexptr)
+         if (*(tokptr + 1) == *pstate->lexptr)
            tokptr++;
          else
            break;
@@ -966,11 +1231,20 @@ match_string_literal (void)
       tempbuf[tempbufindex] = '\0';
       yylval.sval.ptr = tempbuf;
       yylval.sval.length = tempbufindex;
-      lexptr = ++tokptr;
+      pstate->lexptr = ++tokptr;
       return STRING_LITERAL;
     }
 }
 
+/* This is set if a NAME token appeared at the very end of the input
+   string, with no whitespace separating the name from the EOF.  This
+   is used only when parsing to do field name completion.  */
+static bool saw_name_at_eof;
+
+/* This is set if the previously-returned token was a structure
+   operator '%'.  */
+static bool last_was_structop;
+
 /* Read one token, getting characters through lexptr.  */
 
 static int
@@ -978,61 +1252,62 @@ yylex (void)
 {
   int c;
   int namelen;
-  unsigned int i,token;
+  unsigned int token;
   const char *tokstart;
-  
+  bool saw_structop = last_was_structop;
+
+  last_was_structop = false;
+
  retry:
  
-  prev_lexptr = lexptr;
+  pstate->prev_lexptr = pstate->lexptr;
  
-  tokstart = lexptr;
-  
-  /* First of all, let us make sure we are not dealing with the 
+  tokstart = pstate->lexptr;
+
+  /* First of all, let us make sure we are not dealing with the
      special tokens .true. and .false. which evaluate to 1 and 0.  */
-  
-  if (*lexptr == '.')
-    { 
-      for (i = 0; boolean_values[i].name != NULL; i++)
+
+  if (*pstate->lexptr == '.')
+    {
+      for (int i = 0; i < ARRAY_SIZE (boolean_values); i++)
        {
-         if (strncmp (tokstart, boolean_values[i].name,
-                      strlen (boolean_values[i].name)) == 0)
+         if (strncasecmp (tokstart, boolean_values[i].name,
+                          strlen (boolean_values[i].name)) == 0)
            {
-             lexptr += strlen (boolean_values[i].name); 
-             yylval.lval = boolean_values[i].value; 
+             pstate->lexptr += strlen (boolean_values[i].name);
+             yylval.lval = boolean_values[i].value;
              return BOOLEAN_LITERAL;
            }
        }
     }
-  
-  /* See if it is a special .foo. operator.  */
-  
-  for (i = 0; dot_ops[i].operator != NULL; i++)
-    if (strncmp (tokstart, dot_ops[i].operator,
-                strlen (dot_ops[i].operator)) == 0)
+
+  /* See if it is a Fortran operator.  */
+  for (int i = 0; i < ARRAY_SIZE (fortran_operators); i++)
+    if (strncasecmp (tokstart, fortran_operators[i].oper,
+                    strlen (fortran_operators[i].oper)) == 0)
       {
-       lexptr += strlen (dot_ops[i].operator);
-       yylval.opcode = dot_ops[i].opcode;
-       return dot_ops[i].token;
+       gdb_assert (!fortran_operators[i].case_sensitive);
+       pstate->lexptr += strlen (fortran_operators[i].oper);
+       yylval.opcode = fortran_operators[i].opcode;
+       return fortran_operators[i].token;
       }
-  
-  /* See if it is an exponentiation operator.  */
-
-  if (strncmp (tokstart, "**", 2) == 0)
-    {
-      lexptr += 2;
-      yylval.opcode = BINOP_EXP;
-      return STARSTAR;
-    }
 
   switch (c = *tokstart)
     {
     case 0:
+      if (saw_name_at_eof)
+       {
+         saw_name_at_eof = false;
+         return COMPLETE;
+       }
+      else if (pstate->parse_completion && saw_structop)
+       return COMPLETE;
       return 0;
       
     case ' ':
     case '\t':
     case '\n':
-      lexptr++;
+      pstate->lexptr++;
       goto retry;
       
     case '\'':
@@ -1043,27 +1318,27 @@ yylex (void)
       
     case '(':
       paren_depth++;
-      lexptr++;
+      pstate->lexptr++;
       return c;
       
     case ')':
       if (paren_depth == 0)
        return 0;
       paren_depth--;
-      lexptr++;
+      pstate->lexptr++;
       return c;
       
     case ',':
-      if (comma_terminates && paren_depth == 0)
+      if (pstate->comma_terminates && paren_depth == 0)
        return 0;
-      lexptr++;
+      pstate->lexptr++;
       return c;
       
     case '.':
       /* Might be a floating point number.  */
-      if (lexptr[1] < '0' || lexptr[1] > '9')
+      if (pstate->lexptr[1] < '0' || pstate->lexptr[1] > '9')
        goto symbol;            /* Nope, must be a symbol.  */
-      /* FALL THRU into number case.  */
+      /* FALL THRU.  */
       
     case '0':
     case '1':
@@ -1076,7 +1351,7 @@ yylex (void)
     case '8':
     case '9':
       {
-        /* It's a number.  */
+       /* It's a number.  */
        int got_dot = 0, got_e = 0, got_d = 0, toktype;
        const char *p = tokstart;
        int hex = input_radix > 10;
@@ -1117,23 +1392,25 @@ yylex (void)
        toktype = parse_number (pstate, tokstart, p - tokstart,
                                got_dot|got_e|got_d,
                                &yylval);
-        if (toktype == ERROR)
-          {
+       if (toktype == ERROR)
+         {
            char *err_copy = (char *) alloca (p - tokstart + 1);
            
            memcpy (err_copy, tokstart, p - tokstart);
            err_copy[p - tokstart] = 0;
            error (_("Invalid number \"%s\"."), err_copy);
          }
-       lexptr = p;
+       pstate->lexptr = p;
        return toktype;
       }
-      
+
+    case '%':
+      last_was_structop = true;
+      /* Fall through.  */
     case '+':
     case '-':
     case '*':
     case '/':
-    case '%':
     case '|':
     case '&':
     case '^':
@@ -1150,7 +1427,7 @@ yylex (void)
     case '{':
     case '}':
     symbol:
-      lexptr++;
+      pstate->lexptr++;
       return c;
     }
   
@@ -1171,74 +1448,65 @@ yylex (void)
   if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
     return 0;
   
-  lexptr += namelen;
+  pstate->lexptr += namelen;
   
   /* Catch specific keywords.  */
-  
-  for (i = 0; f77_keywords[i].operator != NULL; i++)
-    if (strlen (f77_keywords[i].operator) == namelen
-       && strncmp (tokstart, f77_keywords[i].operator, namelen) == 0)
+
+  for (int i = 0; i < ARRAY_SIZE (f77_keywords); i++)
+    if (strlen (f77_keywords[i].oper) == namelen
+       && ((!f77_keywords[i].case_sensitive
+            && strncasecmp (tokstart, f77_keywords[i].oper, namelen) == 0)
+           || (f77_keywords[i].case_sensitive
+               && strncmp (tokstart, f77_keywords[i].oper, namelen) == 0)))
       {
-       /*      lexptr += strlen(f77_keywords[i].operator); */ 
        yylval.opcode = f77_keywords[i].opcode;
        return f77_keywords[i].token;
       }
-  
+
   yylval.sval.ptr = tokstart;
   yylval.sval.length = namelen;
   
   if (*tokstart == '$')
-    {
-      write_dollar_variable (pstate, yylval.sval);
-      return VARIABLE;
-    }
-  
+    return DOLLAR_VARIABLE;
+
   /* Use token-type TYPENAME for symbols that happen to be defined
      currently as names of types; NAME for other symbols.
      The caller is not constrained to care about the distinction.  */
   {
-    char *tmp = copy_name (yylval.sval);
-    struct symbol *sym;
-    struct field_of_this_result is_a_field_of_this;
+    std::string tmp = copy_name (yylval.sval);
+    struct block_symbol result;
     enum domain_enum_tag lookup_domains[] =
     {
       STRUCT_DOMAIN,
       VAR_DOMAIN,
       MODULE_DOMAIN
     };
-    int i;
     int hextype;
 
-    for (i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
+    for (int i = 0; i < ARRAY_SIZE (lookup_domains); ++i)
       {
-       /* Initialize this in case we *don't* use it in this call; that
-          way we can refer to it unconditionally below.  */
-       memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
-
-       sym = lookup_symbol (tmp, expression_context_block,
-                            lookup_domains[i],
-                            parse_language (pstate)->la_language
-                            == language_cplus ? &is_a_field_of_this : NULL);
-       if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+       result = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
+                               lookup_domains[i], NULL);
+       if (result.symbol && SYMBOL_CLASS (result.symbol) == LOC_TYPEDEF)
          {
-           yylval.tsym.type = SYMBOL_TYPE (sym);
+           yylval.tsym.type = SYMBOL_TYPE (result.symbol);
            return TYPENAME;
          }
 
-       if (sym)
+       if (result.symbol)
          break;
       }
 
     yylval.tsym.type
-      = language_lookup_primitive_type (parse_language (pstate),
-                                       parse_gdbarch (pstate), tmp);
+      = language_lookup_primitive_type (pstate->language (),
+                                       pstate->gdbarch (), tmp.c_str ());
     if (yylval.tsym.type != NULL)
       return TYPENAME;
     
     /* Input names that aren't symbols but ARE valid hex numbers,
        when the input radix permits them, can be names or numbers
        depending on the parse.  Note we support radixes > 16 here.  */
-    if (!sym
+    if (!result.symbol
        && ((tokstart[0] >= 'a' && tokstart[0] < 'a' + input_radix - 10)
            || (tokstart[0] >= 'A' && tokstart[0] < 'A' + input_radix - 10)))
       {
@@ -1246,39 +1514,50 @@ yylex (void)
        hextype = parse_number (pstate, tokstart, namelen, 0, &newlval);
        if (hextype == INT)
          {
-           yylval.ssym.sym = sym;
-           yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
+           yylval.ssym.sym = result;
+           yylval.ssym.is_a_field_of_this = false;
            return NAME_OR_INT;
          }
       }
-    
+
+    if (pstate->parse_completion && *pstate->lexptr == '\0')
+      saw_name_at_eof = true;
+
     /* Any other kind of symbol */
-    yylval.ssym.sym = sym;
-    yylval.ssym.is_a_field_of_this = is_a_field_of_this.type != NULL;
+    yylval.ssym.sym = result;
+    yylval.ssym.is_a_field_of_this = false;
     return NAME;
   }
 }
 
 int
-f_parse (struct parser_state *par_state)
+f_language::parser (struct parser_state *par_state) const
 {
-  int result;
-  struct cleanup *c = make_cleanup_clear_parser_state (&pstate);
-
   /* Setting up the parser state.  */
+  scoped_restore pstate_restore = make_scoped_restore (&pstate);
+  scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
+                                                       parser_debug);
   gdb_assert (par_state != NULL);
   pstate = par_state;
+  last_was_structop = false;
+  saw_name_at_eof = false;
+  paren_depth = 0;
 
-  result = yyparse ();
-  do_cleanups (c);
+  struct type_stack stack;
+  scoped_restore restore_type_stack = make_scoped_restore (&type_stack,
+                                                          &stack);
+
+  int result = yyparse ();
+  if (!result)
+    pstate->set_operation (pstate->pop ());
   return result;
 }
 
-void
-yyerror (char *msg)
+static void
+yyerror (const char *msg)
 {
-  if (prev_lexptr)
-    lexptr = prev_lexptr;
+  if (pstate->prev_lexptr)
+    pstate->lexptr = pstate->prev_lexptr;
 
-  error (_("A %s in expression, near `%s'."), (msg ? msg : "error"), lexptr);
+  error (_("A %s in expression, near `%s'."), msg, pstate->lexptr);
 }
This page took 0.080826 seconds and 4 git commands to generate.