#include "charset.h"
#include "block.h"
#include "cp-support.h"
-#include "dfp.h"
#include "macroscope.h"
#include "objc-lang.h"
#include "typeprint.h"
static int yylex (void);
-void yyerror (char *);
+void yyerror (const char *);
static int type_aggregate_p (struct type *);
LONGEST val;
struct type *type;
} typed_val_int;
- struct {
- DOUBLEST dval;
- struct type *type;
- } typed_val_float;
struct {
gdb_byte val[16];
struct type *type;
- } typed_val_decfloat;
+ } typed_val_float;
struct type *tval;
struct stoken sval;
struct typed_stoken tsval;
#endif
%}
-%type <voidval> exp exp1 type_exp start variable qualified_name lcurly
+%type <voidval> exp exp1 type_exp start variable qualified_name lcurly function_method
%type <lval> rcurly
%type <tval> type typebase
%type <tvec> nonempty_typelist func_mod parameter_typelist
%token <typed_val_int> INT
%token <typed_val_float> FLOAT
-%token <typed_val_decfloat> DECFLOAT
/* Both NAME and TYPENAME tokens represent symbols in the input,
and both convey their data as strings.
write_exp_elt_opcode (pstate, OP_FUNCALL); }
;
+/* This is here to disambiguate with the production for
+ "func()::static_var" further below, which uses
+ function_method_void. */
+exp : exp '(' ')' %prec ARROW
+ { start_arglist ();
+ write_exp_elt_opcode (pstate, OP_FUNCALL);
+ write_exp_elt_longcst (pstate,
+ (LONGEST) end_arglist ());
+ write_exp_elt_opcode (pstate, OP_FUNCALL); }
+ ;
+
+
exp : UNKNOWN_CPP_NAME '('
{
/* This could potentially be a an argument defined
{ arglist_len++; }
;
-exp : exp '(' parameter_typelist ')' const_or_volatile
+function_method: exp '(' parameter_typelist ')' const_or_volatile
{ int i;
VEC (type_ptr) *type_list = $3;
struct type *type_elt;
LONGEST len = VEC_length (type_ptr, type_list);
write_exp_elt_opcode (pstate, TYPE_INSTANCE);
+ /* Save the const/volatile qualifiers as
+ recorded by the const_or_volatile
+ production's actions. */
+ write_exp_elt_longcst (pstate,
+ follow_type_instance_flags ());
write_exp_elt_longcst (pstate, len);
for (i = 0;
VEC_iterate (type_ptr, type_list, i, type_elt);
}
;
+function_method_void: exp '(' ')' const_or_volatile
+ { write_exp_elt_opcode (pstate, TYPE_INSTANCE);
+ /* See above. */
+ write_exp_elt_longcst (pstate,
+ follow_type_instance_flags ());
+ write_exp_elt_longcst (pstate, 0);
+ write_exp_elt_longcst (pstate, 0);
+ write_exp_elt_opcode (pstate, TYPE_INSTANCE);
+ }
+ ;
+
+exp : function_method
+ ;
+
+/* Normally we must interpret "func()" as a function call, instead of
+ a type. The user needs to write func(void) to disambiguate.
+ However, in the "func()::static_var" case, there's no
+ ambiguity. */
+function_method_void_or_typelist: function_method
+ | function_method_void
+ ;
+
+exp : function_method_void_or_typelist COLONCOLON name
+ {
+ write_exp_elt_opcode (pstate, OP_FUNC_STATIC_VAR);
+ write_exp_string (pstate, $3);
+ write_exp_elt_opcode (pstate, OP_FUNC_STATIC_VAR);
+ }
+ ;
+
rcurly : '}'
{ $$ = end_arglist () - 1; }
;
exp : FLOAT
- { write_exp_elt_opcode (pstate, OP_DOUBLE);
+ { write_exp_elt_opcode (pstate, OP_FLOAT);
write_exp_elt_type (pstate, $1.type);
- write_exp_elt_dblcst (pstate, $1.dval);
- write_exp_elt_opcode (pstate, OP_DOUBLE); }
- ;
-
-exp : DECFLOAT
- { write_exp_elt_opcode (pstate, OP_DECFLOAT);
- write_exp_elt_type (pstate, $1.type);
- write_exp_elt_decfloatcst (pstate, $1.val);
- write_exp_elt_opcode (pstate, OP_DECFLOAT); }
+ write_exp_elt_floatcst (pstate, $1.val);
+ write_exp_elt_opcode (pstate, OP_FLOAT); }
;
exp : variable
}
else
{
- struct bound_minimal_symbol msymbol;
char *arg = copy_name ($1.stoken);
- msymbol =
- lookup_bound_minimal_symbol (arg);
- if (msymbol.minsym != NULL)
- write_exp_msymbol (pstate, msymbol);
- else if (!have_full_symbols () && !have_partial_symbols ())
- error (_("No symbol table is loaded. Use the \"file\" command."));
+ bound_minimal_symbol msymbol
+ = lookup_bound_minimal_symbol (arg);
+ if (msymbol.minsym == NULL)
+ {
+ if (!have_full_symbols () && !have_partial_symbols ())
+ error (_("No symbol table is loaded. Use the \"file\" command."));
+ else
+ error (_("No symbol \"%s\" in current context."),
+ copy_name ($1.stoken));
+ }
+
+ /* This minsym might be an alias for
+ another function. See if we can find
+ the debug symbol for the target, and
+ if so, use it instead, since it has
+ return type / prototype info. This
+ is important for example for "p
+ *__errno_location()". */
+ symbol *alias_target
+ = find_function_alias_target (msymbol);
+ if (alias_target != NULL)
+ {
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
+ write_exp_elt_block
+ (pstate, SYMBOL_BLOCK_VALUE (alias_target));
+ write_exp_elt_sym (pstate, alias_target);
+ write_exp_elt_opcode (pstate, OP_VAR_VALUE);
+ }
else
- error (_("No symbol \"%s\" in current context."),
- copy_name ($1.stoken));
+ write_exp_msymbol (pstate, msymbol);
}
}
;
| OPERATOR '>'
{ $$ = operator_stoken (">"); }
| OPERATOR ASSIGN_MODIFY
- { const char *op = "unknown";
+ { const char *op = " unknown";
switch ($2)
{
case BINOP_RSH:
c_print_type ($2, NULL, &buf, -1, 0,
&type_print_raw_options);
- $$ = operator_stoken (buf.c_str ());
+
+ /* 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 ());
}
;
static struct stoken
operator_stoken (const char *op)
{
- static const char *operator_string = "operator";
struct stoken st = { NULL, 0 };
char *buf;
- st.length = strlen (operator_string) + strlen (op);
+ st.length = CP_OPERATOR_LEN + strlen (op);
buf = (char *) malloc (st.length + 1);
- strcpy (buf, operator_string);
+ strcpy (buf, CP_OPERATOR_STR);
strcat (buf, op);
st.ptr = buf;
if (parsed_float)
{
- /* If it ends at "df", "dd" or "dl", take it as type of decimal floating
- point. Return DECFLOAT. */
-
+ /* Handle suffixes for decimal floating-point: "df", "dd" or "dl". */
if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'f')
{
- p[len - 2] = '\0';
- putithere->typed_val_decfloat.type
+ putithere->typed_val_float.type
= parse_type (par_state)->builtin_decfloat;
- decimal_from_string (putithere->typed_val_decfloat.val, 4,
- gdbarch_byte_order (parse_gdbarch (par_state)),
- p);
- p[len - 2] = 'd';
- return DECFLOAT;
+ len -= 2;
}
-
- if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
+ else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'd')
{
- p[len - 2] = '\0';
- putithere->typed_val_decfloat.type
+ putithere->typed_val_float.type
= parse_type (par_state)->builtin_decdouble;
- decimal_from_string (putithere->typed_val_decfloat.val, 8,
- gdbarch_byte_order (parse_gdbarch (par_state)),
- p);
- p[len - 2] = 'd';
- return DECFLOAT;
+ len -= 2;
}
-
- if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
+ else if (len >= 2 && p[len - 2] == 'd' && p[len - 1] == 'l')
{
- p[len - 2] = '\0';
- putithere->typed_val_decfloat.type
+ putithere->typed_val_float.type
= parse_type (par_state)->builtin_declong;
- decimal_from_string (putithere->typed_val_decfloat.val, 16,
- gdbarch_byte_order (parse_gdbarch (par_state)),
- p);
- p[len - 2] = 'd';
- return DECFLOAT;
+ len -= 2;
+ }
+ /* Handle suffixes: 'f' for float, 'l' for long double. */
+ else if (len >= 1 && tolower (p[len - 1]) == 'f')
+ {
+ putithere->typed_val_float.type
+ = parse_type (par_state)->builtin_float;
+ len -= 1;
+ }
+ else if (len >= 1 && tolower (p[len - 1]) == 'l')
+ {
+ putithere->typed_val_float.type
+ = parse_type (par_state)->builtin_long_double;
+ len -= 1;
+ }
+ /* Default type for floating-point literals is double. */
+ else
+ {
+ putithere->typed_val_float.type
+ = parse_type (par_state)->builtin_double;
}
- if (! parse_c_float (parse_gdbarch (par_state), p, len,
- &putithere->typed_val_float.dval,
- &putithere->typed_val_float.type))
- return ERROR;
+ if (!parse_float (p, len,
+ putithere->typed_val_float.type,
+ putithere->typed_val_float.val))
+ return ERROR;
return FLOAT;
}
struct token
{
- char *oper;
+ const char *oper;
int token;
enum exp_opcode opcode;
token_flags flags;
/* Temporary storage for c_lex; this holds symbol names as they are
built up. */
-static struct obstack name_obstack;
+auto_obstack name_obstack;
/* Classify a NAME token. The contents of the token are in `yylval'.
Updates yylval and returns the new token type. BLOCK is the block
current = *VEC_index (token_and_value, token_fifo, next_to_examine);
++next_to_examine;
- obstack_free (&name_obstack, obstack_base (&name_obstack));
+ name_obstack.clear ();
checkpoint = 0;
if (current.token == FILENAME)
search_block = current.value.bval;
struct cleanup *back_to;
/* Setting up the parser state. */
+ scoped_restore pstate_restore = make_scoped_restore (&pstate);
gdb_assert (par_state != NULL);
pstate = par_state;
+ /* Note that parsing (within yyparse) freely installs cleanups
+ assuming they'll be run here (below). */
+
back_to = make_cleanup (free_current_contents, &expression_macro_scope);
- make_cleanup_clear_parser_state (&pstate);
/* Set up the scope for macro expansion. */
expression_macro_scope = NULL;
gdb_assert (! macro_original_text);
make_cleanup (scan_macro_cleanup, 0);
- make_cleanup_restore_integer (&yydebug);
- yydebug = parser_debug;
+ scoped_restore restore_yydebug = make_scoped_restore (&yydebug,
+ parser_debug);
/* Initialize some state used by the lexer. */
last_was_structop = 0;
VEC_free (token_and_value, token_fifo);
popping = 0;
- obstack_init (&name_obstack);
- make_cleanup_obstack_free (&name_obstack);
+ name_obstack.clear ();
result = yyparse ();
do_cleanups (back_to);
#endif
void
-yyerror (char *msg)
+yyerror (const char *msg)
{
if (prev_lexptr)
lexptr = prev_lexptr;