/* YACC parser for C expressions, for GDB.
- Copyright (C) 1986-2014 Free Software Foundation, Inc.
+ Copyright (C) 1986-2015 Free Software Foundation, Inc.
This file is part of GDB.
with include files (<malloc.h> and <stdlib.h> for example) just became
too messy, particularly when such includes can be inserted at random
times by the parser generator. */
-
+
%{
#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;
E.g. "c" when input_radix==16. Depending on the parse, it will be
turned into a name or into a number. */
-%token <ssym> NAME_OR_INT
+%token <ssym> NAME_OR_INT
%token OPERATOR
%token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON
%left '*' '/' '%'
%right UNARY INCREMENT DECREMENT
%right ARROW ARROW_STAR '.' DOT_STAR '[' OBJC_LBRAC '('
-%token <ssym> BLOCKNAME
+%token <ssym> BLOCKNAME
%token <bval> FILENAME
%type <bval> block
%left COLONCOLON
{ add_msglist(0, 0); }
;
-exp : exp '('
+exp : exp '('
/* This is to save the value of arglist_len
being accumulated by an outer function call. */
{ start_arglist (); }
exp : exp '?' exp ':' exp %prec '?'
{ write_exp_elt_opcode (pstate, TERNOP_COND); }
;
-
+
exp : exp '=' exp
{ write_exp_elt_opcode (pstate, BINOP_ASSIGN); }
;
;
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); }
;
;
/* C++. */
-exp : TRUEKEYWORD
+exp : TRUEKEYWORD
{ write_exp_elt_opcode (pstate, OP_LONG);
write_exp_elt_type (pstate,
parse_type (pstate)->builtin_bool);
write_exp_elt_opcode (pstate, OP_LONG); }
;
-exp : FALSEKEYWORD
+exp : FALSEKEYWORD
{ write_exp_elt_opcode (pstate, OP_LONG);
write_exp_elt_type (pstate,
parse_type (pstate)->builtin_bool);
{
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);
if (symbol_read_needs_frame (sym))
{
if (innermost_block == 0
- || contained_in (block_found,
+ || contained_in (block_found,
innermost_block))
innermost_block = block_found;
}
;
const_or_volatile_or_space_identifier_noopt: cv_with_space_id
- | const_or_volatile_noopt
+ | const_or_volatile_noopt
;
-const_or_volatile_or_space_identifier:
+const_or_volatile_or_space_identifier:
const_or_volatile_or_space_identifier_noopt
|
;
ptr_operator '*'
{ insert_type (tp_pointer); }
const_or_volatile_or_space_identifier
- | '*'
+ | '*'
{ insert_type (tp_pointer); }
const_or_volatile_or_space_identifier
| '&'
abs_decl: ptr_operator_ts direct_abs_decl
{ $$ = append_type_stack ($2, $1); }
- | ptr_operator_ts
+ | ptr_operator_ts
| direct_abs_decl
;
{ $$ = lookup_unsigned_typename (parse_language (pstate),
parse_gdbarch (pstate),
"short"); }
- | SHORT UNSIGNED
+ | SHORT UNSIGNED
{ $$ = lookup_unsigned_typename (parse_language (pstate),
parse_gdbarch (pstate),
"short"); }
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;
}
"int"); }
/* It appears that this rule for templates is never
reduced; template recognition happens by lookahead
- in the token processing code in yylex. */
+ in the token processing code in yylex. */
| TEMPLATE name '<' type '>'
{ $$ = lookup_template_type(copy_name($2), $4,
expression_context_block);
}
- | const_or_volatile_or_space_identifier_noopt typebase
+ | const_or_volatile_or_space_identifier_noopt typebase
{ $$ = follow_types ($2); }
- | typebase const_or_volatile_or_space_identifier_noopt
+ | typebase const_or_volatile_or_space_identifier_noopt
{ $$ = follow_types ($1); }
;
| VOLATILE_KEYWORD CONST_KEYWORD
;
-const_or_volatile_noopt: const_and_volatile
+const_or_volatile_noopt: const_and_volatile
{ insert_type (tp_const);
- insert_type (tp_volatile);
+ insert_type (tp_volatile);
}
| CONST_KEYWORD
{ insert_type (tp_const); }
}
/* Returns a stoken of the operator name given by OP (which does not
- include the string "operator"). */
+ include the string "operator"). */
+
static struct stoken
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
}
/* Handle base-switching prefixes 0x, 0t, 0d, 0 */
- if (p[0] == '0')
+ if (p[0] == '0' && len > 1)
switch (p[1])
{
case 'x':
else
{
int shift;
- if (sizeof (ULONGEST) * HOST_CHAR_BIT
+ if (sizeof (ULONGEST) * HOST_CHAR_BIT
< gdbarch_long_long_bit (parse_gdbarch (par_state)))
/* A long long does not fit in a LONGEST. */
shift = (sizeof (ULONGEST) * HOST_CHAR_BIT - 1);
/* If the high bit of the worked out type is set then this number
has to be unsigned. */
- if (unsigned_p || (n & high_bit))
+ if (unsigned_p || (n & high_bit))
{
putithere->typed_val_int.type = unsigned_type;
}
- else
+ else
{
putithere->typed_val_int.type = signed_type;
}
stored in VALUE. This returns a token value, either STRING or
CHAR, depending on what was parsed. *HOST_CHARS is set to the
number of host characters in the literal. */
+
static int
parse_string_or_char (const char *tokptr, const char **outptr,
struct typed_stoken *value, int *host_chars)
lexptr = copy;
}
-
static int
scanning_macro_expansion (void)
{
return macro_original_text != 0;
}
-
-static void
+static void
finished_macro_expansion (void)
{
/* There'd better be something to pop back to. */
macro_original_text = 0;
}
-
static void
scan_macro_cleanup (void *dummy)
{
that we look ahead only when the '<' adjoins non-whitespace
characters; for comparison expressions, e.g. "a < b > c",
there must be spaces before the '<', etc. */
-
const char *p = find_template_name_end (tokstart + namelen);
if (p)
in which lookups start; this can be NULL to mean the global scope.
IS_QUOTED_NAME is non-zero if the name token was originally quoted
in single quotes. */
+
static int
classify_name (struct parser_state *par_state, const struct block *block,
int is_quoted_name)
we can refer to it unconditionally below. */
memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
- sym = lookup_symbol (copy, block, VAR_DOMAIN,
+ sym = lookup_symbol (copy, block, VAR_DOMAIN,
parse_language (par_state)->la_name_of_this
? &is_a_field_of_this : NULL);
symtab = lookup_symtab (copy);
if (symtab)
{
- yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab),
+ yylval.bval = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab),
STATIC_BLOCK);
return FILENAME;
}
return TYPENAME;
}
- yylval.tsym.type
- = language_lookup_primitive_type_by_name (parse_language (par_state),
- parse_gdbarch (par_state),
- copy);
- if (yylval.tsym.type != NULL)
- return TYPENAME;
-
/* See if it's an ObjC classname. */
if (parse_language (par_state)->la_language == language_objc && !sym)
{
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);
relative to the `this' pointer. */
if (yylval.ssym.sym == NULL)
{
- struct type *base_type = find_type_baseclass_by_name (type, copy);
+ struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
if (base_type != NULL)
{
named COPY when we really wanted a base class of the same name.
Double-check this case by looking for a base class. */
{
- struct type *base_type = find_type_baseclass_by_name (type, copy);
+ struct type *base_type = cp_find_type_baseclass_by_name (type, copy);
if (base_type != NULL)
{
return ERROR;
case LOC_TYPEDEF:
- yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);;
+ yylval.tsym.type = SYMBOL_TYPE (yylval.ssym.sym);
return TYPENAME;
default:
problem in our parsing approach, where the parser could not
distinguish between qualified names and qualified types at the
right point.
-
+
This approach is still not ideal, because it mishandles template
types. See the comment in lex_one_token for an example. However,
this is still an improvement over the earlier approach, and will
suffice until we move to better parsing technology. */
+
static int
yylex (void)
{
current.token = classification;
last_was_coloncolon = 0;
-
+
if (classification == NAME)
break;