gdb/mi: make current_token a field of mi_interp
[binutils-gdb.git] / gdb / ada-lex.l
index 33a08eaa93b8cb1b30a1915da5e82feeda5f815f..0547b704eaf4d59a1b777eef708f2adb3ce3bcde 100644 (file)
@@ -1,5 +1,5 @@
 /* FLEX lexer for Ada expressions, for GDB. -*- c++ -*-
-   Copyright (C) 1994-2022 Free Software Foundation, Inc.
+   Copyright (C) 1994-2023 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -179,15 +179,15 @@ static int paren_depth;
                }
 
 <INITIAL>"'"({GRAPHIC}|\")"'" {
-                  yylval.typed_val.val = yytext[1];
-                  yylval.typed_val.type = type_for_char (pstate, yytext[1]);
+                  yylval.typed_char.val = yytext[1];
+                  yylval.typed_char.type = type_for_char (pstate, yytext[1]);
                   return CHARLIT;
                }
 
 <INITIAL>"'[\""{HEXDIG}{2,}"\"]'"   {
                    ULONGEST v = strtoulst (yytext+3, nullptr, 16);
-                  yylval.typed_val.val = v;
-                   yylval.typed_val.type = type_for_char (pstate, v);
+                  yylval.typed_char.val = v;
+                   yylval.typed_char.type = type_for_char (pstate, v);
                   return CHARLIT;
                }
 
@@ -371,7 +371,7 @@ canonicalizeNumeral (char *s1, const char *s2)
 /* Interprets the prefix of NUM that consists of digits of the given BASE
    as an integer of that BASE, with the string EXP as an exponent.
    Puts value in yylval, and returns INT, if the string is valid.  Causes
-   an error if the number is improperly formated.   BASE, if NULL, defaults
+   an error if the number is improperly formatted.   BASE, if NULL, defaults
    to "10", and EXP to "1".  The EXP does not contain a leading 'e' or 'E'.
  */
 
@@ -422,14 +422,14 @@ processInt (struct parser_state *par_state, const char *base0,
       int dig = fromhex (*num0);
       if (dig >= base)
        error (_("Invalid digit `%c' in based literal"), *num0);
-      mpz_mul_ui (result.val, result.val, base);
-      mpz_add_ui (result.val, result.val, dig);
+      result *= base;
+      result += dig;
       ++num0;
     }
 
   while (exp > 0)
     {
-      mpz_mul_ui (result.val, result.val, base);
+      result *= base;
       exp -= 1;
     }
 
@@ -455,43 +455,44 @@ processInt (struct parser_state *par_state, const char *base0,
 
       yylval.typed_val_float.type = fp_type;
       result.write (gdb::make_array_view (yylval.typed_val_float.val,
-                                         TYPE_LENGTH (fp_type)),
+                                         fp_type->length ()),
                    type_byte_order (fp_type),
                    true);
 
       return FLOAT;
     }
 
-  gdb_mpz maxval (ULONGEST_MAX);
-  if (mpz_cmp (result.val, maxval.val) > 0)
-    error (_("Integer literal out of range"));
-
-  ULONGEST value = result.as_integer<ULONGEST> ();
-  if ((value >> (gdbarch_int_bit (par_state->gdbarch ())-1)) == 0)
-    yylval.typed_val.type = type_int (par_state);
-  else if ((value >> (gdbarch_long_bit (par_state->gdbarch ())-1)) == 0)
-    yylval.typed_val.type = type_long (par_state);
-  else if (((value >> (gdbarch_long_bit (par_state->gdbarch ())-1)) >> 1) == 0)
-    {
-      /* We have a number representable as an unsigned integer quantity.
-         For consistency with the C treatment, we will treat it as an
-        anonymous modular (unsigned) quantity.  Alas, the types are such
-        that we need to store .val as a signed quantity.  Sorry
-         for the mess, but C doesn't officially guarantee that a simple
-         assignment does the trick (no, it doesn't; read the reference manual).
-       */
-      yylval.typed_val.type
-       = builtin_type (par_state->gdbarch ())->builtin_unsigned_long;
-      if (value & LONGEST_SIGN)
-       yylval.typed_val.val =
-         (LONGEST) (value & ~LONGEST_SIGN)
-         - (LONGEST_SIGN>>1) - (LONGEST_SIGN>>1);
-      else
-       yylval.typed_val.val = (LONGEST) value;
-      return INT;
-    }
+  int_storage.emplace_back (new gdb_mpz (std::move (result)));
+  const gdb_mpz *value = int_storage.back ().get ();
+
+  int int_bits = gdbarch_int_bit (par_state->gdbarch ());
+  int long_bits = gdbarch_long_bit (par_state->gdbarch ());
+  int long_long_bits = gdbarch_long_long_bit (par_state->gdbarch ());
+
+  if (fits_in_type (1, *value, int_bits, true))
+    yylval.typed_val.type = parse_type (par_state)->builtin_int;
+  else if (fits_in_type (1, *value, long_bits, true))
+    yylval.typed_val.type = parse_type (par_state)->builtin_long;
+  else if (fits_in_type (1, *value, long_bits, false))
+    yylval.typed_val.type
+      = builtin_type (par_state->gdbarch ())->builtin_unsigned_long;
+  else if (fits_in_type (1, *value, long_long_bits, true))
+    yylval.typed_val.type = parse_type (par_state)->builtin_long_long;
+  else if (fits_in_type (1, *value, long_long_bits, false))
+    yylval.typed_val.type
+      = builtin_type (par_state->gdbarch ())->builtin_unsigned_long_long;
+  else if (fits_in_type (1, *value, 128, true))
+    yylval.typed_val.type
+      = language_lookup_primitive_type (par_state->language (),
+                                       par_state->gdbarch (),
+                                       "long_long_long_integer");
+  else if (fits_in_type (1, *value, 128, false))
+    yylval.typed_val.type
+      = language_lookup_primitive_type (par_state->language (),
+                                       par_state->gdbarch (),
+                                       "unsigned_long_long_long_integer");
   else
-    yylval.typed_val.type = type_long_long (par_state);
+    error (_("Integer literal out of range"));
 
   yylval.typed_val.val = value;
   return INT;
@@ -500,7 +501,7 @@ processInt (struct parser_state *par_state, const char *base0,
 static int
 processReal (struct parser_state *par_state, const char *num0)
 {
-  yylval.typed_val_float.type = type_long_double (par_state);
+  yylval.typed_val_float.type = parse_type (par_state)->builtin_long_double;
 
   bool parsed = parse_float (num0, strlen (num0),
                             yylval.typed_val_float.type,
@@ -683,6 +684,8 @@ attributes[] = {
   { "size", TICK_SIZE },
   { "tag", TICK_TAG },
   { "val", TICK_VAL },
+  { "enum_rep", TICK_ENUM_REP },
+  { "enum_val", TICK_ENUM_VAL },
 };
 
 /* Return the syntactic code corresponding to the attribute name or