Correct invalid assumptions made by (mostly) DWARF-2 tests
[deliverable/binutils-gdb.git] / gdb / c-exp.y
index fc798079e3b1571c7ea11e28b317e32051888fbe..92ff3b6d4e4b9d7c24c415f9893a7cda51303a4d 100644 (file)
@@ -36,7 +36,6 @@
 %{
 
 #include "defs.h"
-#include <string.h>
 #include <ctype.h>
 #include "expression.h"
 #include "value.h"
@@ -50,7 +49,6 @@
 #include "block.h"
 #include "cp-support.h"
 #include "dfp.h"
-#include "gdb_assert.h"
 #include "macroscope.h"
 #include "objc-lang.h"
 #include "typeprint.h"
@@ -129,6 +127,8 @@ static int yylex (void);
 
 void yyerror (char *);
 
+static int type_aggregate_p (struct type *);
+
 %}
 
 /* Although the yacc "value" of an expression is not used,
@@ -156,7 +156,7 @@ void yyerror (char *);
     struct ttype tsym;
     struct symtoken ssym;
     int voidval;
-    struct block *bval;
+    const struct block *bval;
     enum exp_opcode opcode;
 
     struct stoken_vector svec;
@@ -787,14 +787,22 @@ exp       :       SELECTOR '(' name ')'
        ;
 
 exp    :       SIZEOF '(' type ')'     %prec UNARY
-                       { write_exp_elt_opcode (pstate, OP_LONG);
+                       { struct type *type = $3;
+                         write_exp_elt_opcode (pstate, OP_LONG);
                          write_exp_elt_type (pstate, lookup_signed_typename
                                              (parse_language (pstate),
                                               parse_gdbarch (pstate),
                                               "int"));
-                         CHECK_TYPEDEF ($3);
+                         CHECK_TYPEDEF (type);
+
+                           /* $5.3.3/2 of the C++ Standard (n3290 draft)
+                              says of sizeof:  "When applied to a reference
+                              or a reference type, the result is the size of
+                              the referenced type."  */
+                         if (TYPE_CODE (type) == TYPE_CODE_REF)
+                           type = check_typedef (TYPE_TARGET_TYPE (type));
                          write_exp_elt_longcst (pstate,
-                                                (LONGEST) TYPE_LENGTH ($3));
+                                                (LONGEST) TYPE_LENGTH (type));
                          write_exp_elt_opcode (pstate, OP_LONG); }
        ;
 
@@ -978,9 +986,7 @@ qualified_name:     TYPENAME COLONCOLON name
                        {
                          struct type *type = $1.type;
                          CHECK_TYPEDEF (type);
-                         if (TYPE_CODE (type) != TYPE_CODE_STRUCT
-                             && TYPE_CODE (type) != TYPE_CODE_UNION
-                             && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
+                         if (!type_aggregate_p (type))
                            error (_("`%s' is not defined as an aggregate type."),
                                   TYPE_SAFE_NAME (type));
 
@@ -996,9 +1002,7 @@ qualified_name:    TYPENAME COLONCOLON name
                          char *buf;
 
                          CHECK_TYPEDEF (type);
-                         if (TYPE_CODE (type) != TYPE_CODE_STRUCT
-                             && TYPE_CODE (type) != TYPE_CODE_UNION
-                             && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
+                         if (!type_aggregate_p (type))
                            error (_("`%s' is not defined as an aggregate type."),
                                   TYPE_SAFE_NAME (type));
                          buf = alloca ($4.length + 2);
@@ -1349,12 +1353,12 @@ typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
                                              expression_context_block); }
        |       CLASS COMPLETE
                        {
-                         mark_completion_tag (TYPE_CODE_CLASS, "", 0);
+                         mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
                          $$ = NULL;
                        }
        |       CLASS name COMPLETE
                        {
-                         mark_completion_tag (TYPE_CODE_CLASS, $2.ptr,
+                         mark_completion_tag (TYPE_CODE_STRUCT, $2.ptr,
                                               $2.length);
                          $$ = NULL;
                        }
@@ -1693,6 +1697,18 @@ operator_stoken (const char *op)
   return st;
 };
 
+/* Return true if the type is aggregate-like.  */
+
+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
+             && TYPE_DECLARED_CLASS (type)));
+}
+
 /* Validate a parameter typelist.  */
 
 static void
@@ -1808,7 +1824,7 @@ parse_number (struct parser_state *par_state,
     }
 
   /* Handle base-switching prefixes 0x, 0t, 0d, 0 */
-  if (p[0] == '0')
+  if (p[0] == '0' && len > 1)
     switch (p[1])
       {
       case 'x':
@@ -2912,7 +2928,7 @@ classify_name (struct parser_state *par_state, const struct block *block,
          symtab = lookup_symtab (copy);
          if (symtab)
            {
-             yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab),
+             yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab),
                                               STATIC_BLOCK);
              return FILENAME;
            }
@@ -2992,9 +3008,7 @@ classify_inner_name (struct parser_state *par_state,
     return classify_name (par_state, block, 0);
 
   type = check_typedef (context);
-  if (TYPE_CODE (type) != TYPE_CODE_STRUCT
-      && TYPE_CODE (type) != TYPE_CODE_UNION
-      && TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
+  if (!type_aggregate_p (type))
     return ERROR;
 
   copy = copy_name (yylval.ssym.stoken);
This page took 0.026174 seconds and 4 git commands to generate.