%{
#include "defs.h"
-#include <string.h>
#include <ctype.h>
#include "expression.h"
#include "value.h"
#include "block.h"
#include "cp-support.h"
#include "dfp.h"
-#include "gdb_assert.h"
#include "macroscope.h"
#include "objc-lang.h"
#include "typeprint.h"
void yyerror (char *);
+static int type_aggregate_p (struct type *);
+
%}
/* Although the yacc "value" of an expression is not used,
struct ttype tsym;
struct symtoken ssym;
int voidval;
- struct block *bval;
+ const struct block *bval;
enum exp_opcode opcode;
struct stoken_vector svec;
;
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); }
;
{
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));
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);
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
}
/* Handle base-switching prefixes 0x, 0t, 0d, 0 */
- if (p[0] == '0')
+ if (p[0] == '0' && len > 1)
switch (p[1])
{
case 'x':
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);