Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index c2531b9bffc47f9576751867f81ea15af0ccdb95..5ec84eb8ed7abcd09287c2aaab10a53f5095a44e 100644 (file)
@@ -175,7 +175,7 @@ static void c_print_token (FILE *file, int type, YYSTYPE value);
 
 %type <voidval> exp exp1 type_exp start variable qualified_name lcurly function_method
 %type <lval> rcurly
-%type <tval> type typebase
+%type <tval> type typebase scalar_type
 %type <tvec> nonempty_typelist func_mod parameter_typelist
 /* %type <bval> block */
 
@@ -239,6 +239,7 @@ static void c_print_token (FILE *file, int type, YYSTYPE value);
    legal basetypes.  */
 %token SIGNED_KEYWORD LONG SHORT INT_KEYWORD CONST_KEYWORD VOLATILE_KEYWORD DOUBLE_KEYWORD
 %token RESTRICT ATOMIC
+%token FLOAT_KEYWORD COMPLEX
 
 %token <sval> DOLLAR_VARIABLE
 
@@ -1331,20 +1332,11 @@ func_mod:       '(' ')'
 type   :       ptype
        ;
 
-/* Implements (approximately): (type-qualifier)* type-specifier.
+/* A helper production that recognizes scalar types that can validly
+   be used with _Complex.  */
 
-   When type-specifier is only ever a single word, like 'float' then these
-   arrive as pre-built TYPENAME tokens thanks to the classify_name
-   function.  However, when a type-specifier can contain multiple words,
-   for example 'double' can appear as just 'double' or 'long double', and
-   similarly 'long' can appear as just 'long' or in 'long double', then
-   these type-specifiers are parsed into their own tokens in the function
-   lex_one_token and the ident_tokens array.  These separate tokens are all
-   recognised here.  */
-typebase
-       :       TYPENAME
-                       { $$ = $1.type; }
-       |       INT_KEYWORD
+scalar_type:
+               INT_KEYWORD
                        { $$ = lookup_signed_typename (pstate->language (),
                                                       "int"); }
        |       LONG
@@ -1427,11 +1419,49 @@ typebase
                                                "double",
                                                NULL,
                                                0); }
+       |       FLOAT_KEYWORD
+                       { $$ = lookup_typename (pstate->language (),
+                                               "float",
+                                               NULL,
+                                               0); }
        |       LONG DOUBLE_KEYWORD
                        { $$ = lookup_typename (pstate->language (),
                                                "long double",
                                                NULL,
                                                0); }
+       |       UNSIGNED type_name
+                       { $$ = lookup_unsigned_typename (pstate->language (),
+                                                        $2.type->name ()); }
+       |       UNSIGNED
+                       { $$ = lookup_unsigned_typename (pstate->language (),
+                                                        "int"); }
+       |       SIGNED_KEYWORD type_name
+                       { $$ = lookup_signed_typename (pstate->language (),
+                                                      $2.type->name ()); }
+       |       SIGNED_KEYWORD
+                       { $$ = lookup_signed_typename (pstate->language (),
+                                                      "int"); }
+       ;
+
+/* Implements (approximately): (type-qualifier)* type-specifier.
+
+   When type-specifier is only ever a single word, like 'float' then these
+   arrive as pre-built TYPENAME tokens thanks to the classify_name
+   function.  However, when a type-specifier can contain multiple words,
+   for example 'double' can appear as just 'double' or 'long double', and
+   similarly 'long' can appear as just 'long' or in 'long double', then
+   these type-specifiers are parsed into their own tokens in the function
+   lex_one_token and the ident_tokens array.  These separate tokens are all
+   recognised here.  */
+typebase
+       :       TYPENAME
+                       { $$ = $1.type; }
+       |       scalar_type
+                       { $$ = $1; }
+       |       COMPLEX scalar_type
+                       {
+                         $$ = init_complex_type (nullptr, $2);
+                       }
        |       STRUCT name
                        { $$
                            = lookup_struct (copy_name ($2).c_str (),
@@ -1498,18 +1528,6 @@ typebase
                                                       $2.length);
                          $$ = NULL;
                        }
-       |       UNSIGNED type_name
-                       { $$ = lookup_unsigned_typename (pstate->language (),
-                                                        TYPE_NAME($2.type)); }
-       |       UNSIGNED
-                       { $$ = lookup_unsigned_typename (pstate->language (),
-                                                        "int"); }
-       |       SIGNED_KEYWORD type_name
-                       { $$ = lookup_signed_typename (pstate->language (),
-                                                      TYPE_NAME($2.type)); }
-       |       SIGNED_KEYWORD
-                       { $$ = lookup_signed_typename (pstate->language (),
-                                                      "int"); }
                 /* It appears that this rule for templates is never
                    reduced; template recognition happens by lookahead
                    in the token processing code in yylex. */
@@ -1721,13 +1739,14 @@ oper:   OPERATOR NEW
 
                          c_print_type ($2, NULL, &buf, -1, 0,
                                        &type_print_raw_options);
+                         std::string name = std::move (buf.string ());
 
                          /* This also needs canonicalization.  */
-                         std::string canon
-                           = cp_canonicalize_string (buf.c_str ());
-                         if (canon.empty ())
-                           canon = std::move (buf.string ());
-                         $$ = operator_stoken ((" " + canon).c_str ());
+                         gdb::unique_xmalloc_ptr<char> canon
+                           = cp_canonicalize_string (name.c_str ());
+                         if (canon != nullptr)
+                           name = canon.get ();
+                         $$ = operator_stoken ((" " + name).c_str ());
                        }
        ;
 
@@ -1735,12 +1754,11 @@ oper:   OPERATOR NEW
    match the 'name' rule to appear as fields within a struct.  The example
    that initially motivated this was the RISC-V target which models the
    floating point registers as a union with fields called 'float' and
-   'double'.  The 'float' string becomes a TYPENAME token and can appear
-   anywhere a 'name' can, however 'double' is its own token,
-   DOUBLE_KEYWORD, and doesn't match the 'name' rule.*/
+   'double'.  */
 field_name
        :       name
        |       DOUBLE_KEYWORD { $$ = typename_stoken ("double"); }
+       |       FLOAT_KEYWORD { $$ = typename_stoken ("float"); }
        |       INT_KEYWORD { $$ = typename_stoken ("int"); }
        |       LONG { $$ = typename_stoken ("long"); }
        |       SHORT { $$ = typename_stoken ("short"); }
@@ -1834,10 +1852,10 @@ typename_stoken (const char *type)
 static int
 type_aggregate_p (struct type *type)
 {
-  return (TYPE_CODE (type) == TYPE_CODE_STRUCT
-         || TYPE_CODE (type) == TYPE_CODE_UNION
-         || TYPE_CODE (type) == TYPE_CODE_NAMESPACE
-         || (TYPE_CODE (type) == TYPE_CODE_ENUM
+  return (type->code () == TYPE_CODE_STRUCT
+         || type->code () == TYPE_CODE_UNION
+         || type->code () == TYPE_CODE_NAMESPACE
+         || (type->code () == TYPE_CODE_ENUM
              && TYPE_DECLARED_CLASS (type)));
 }
 
@@ -1852,7 +1870,7 @@ check_parameter_typelist (std::vector<struct type *> *params)
   for (ix = 0; ix < params->size (); ++ix)
     {
       type = (*params)[ix];
-      if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID)
+      if (type != NULL && check_typedef (type)->code () == TYPE_CODE_VOID)
        {
          if (ix == 0)
            {
@@ -2472,7 +2490,7 @@ static const struct token tokentab2[] =
 /* Identifier-like tokens.  Only type-specifiers than can appear in
    multi-word type names (for example 'double' can appear in 'long
    double') need to be listed here.  type-specifiers that are only ever
-   single word (like 'float') are handled by the classify_name function.  */
+   single word (like 'char') are handled by the classify_name function.  */
 static const struct token ident_tokens[] =
   {
     {"unsigned", UNSIGNED, OP_NULL, 0},
@@ -2484,6 +2502,7 @@ static const struct token ident_tokens[] =
     {"_Alignof", ALIGNOF, OP_NULL, 0},
     {"alignof", ALIGNOF, OP_NULL, FLAG_CXX},
     {"double", DOUBLE_KEYWORD, OP_NULL, 0},
+    {"float", FLOAT_KEYWORD, OP_NULL, 0},
     {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX},
     {"class", CLASS, OP_NULL, FLAG_CXX},
     {"union", UNION, OP_NULL, 0},
@@ -2495,6 +2514,9 @@ static const struct token ident_tokens[] =
     {"_Atomic", ATOMIC, OP_NULL, 0},
     {"enum", ENUM, OP_NULL, 0},
     {"long", LONG, OP_NULL, 0},
+    {"_Complex", COMPLEX, OP_NULL, 0},
+    {"__complex__", COMPLEX, OP_NULL, 0},
+
     {"true", TRUEKEYWORD, OP_NULL, FLAG_CXX},
     {"int", INT_KEYWORD, OP_NULL, 0},
     {"new", NEW, OP_NULL, FLAG_CXX},
@@ -2726,7 +2748,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
     case '9':
       {
        /* It's a number.  */
-       int got_dot = 0, got_e = 0, toktype;
+       int got_dot = 0, got_e = 0, got_p = 0, toktype;
        const char *p = tokstart;
        int hex = input_radix > 10;
 
@@ -2746,13 +2768,16 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
            /* This test includes !hex because 'e' is a valid hex digit
               and thus does not indicate a floating point number when
               the radix is hex.  */
-           if (!hex && !got_e && (*p == 'e' || *p == 'E'))
+           if (!hex && !got_e && !got_p && (*p == 'e' || *p == 'E'))
              got_dot = got_e = 1;
+           else if (!got_e && !got_p && (*p == 'p' || *p == 'P'))
+             got_dot = got_p = 1;
            /* This test does not include !hex, because a '.' always indicates
               a decimal floating point number regardless of the radix.  */
            else if (!got_dot && *p == '.')
              got_dot = 1;
-           else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
+           else if (((got_e && (p[-1] == 'e' || p[-1] == 'E'))
+                     || (got_p && (p[-1] == 'p' || p[-1] == 'P')))
                     && (*p == '-' || *p == '+'))
              /* This is the sign of the exponent, not the end of the
                 number.  */
@@ -2765,7 +2790,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
              break;
          }
        toktype = parse_number (par_state, tokstart, p - tokstart,
-                               got_dot|got_e, &yylval);
+                               got_dot | got_e | got_p, &yylval);
         if (toktype == ERROR)
          {
            char *err_copy = (char *) alloca (p - tokstart + 1);
This page took 0.028301 seconds and 4 git commands to generate.