/* YACC parser for C expressions, for GDB.
- Copyright (C) 1986, 1989-2000, 2003-2004, 2006-2012 Free Software
- Foundation, Inc.
+ Copyright (C) 1986-2013 Free Software Foundation, Inc.
This file is part of GDB.
#include "macroscope.h"
#include "objc-lang.h"
#include "typeprint.h"
+#include "cp-abi.h"
#define parse_type builtin_type (parse_gdbarch)
&& TYPE_CODE (type) != TYPE_CODE_UNION
&& TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
error (_("`%s' is not defined as an aggregate type."),
- TYPE_NAME (type));
+ TYPE_SAFE_NAME (type));
write_exp_elt_opcode (OP_SCOPE);
write_exp_elt_type (type);
&& TYPE_CODE (type) != TYPE_CODE_UNION
&& TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
error (_("`%s' is not defined as an aggregate type."),
- TYPE_NAME (type));
+ TYPE_SAFE_NAME (type));
tmp_token.ptr = (char*) alloca ($4.length + 2);
tmp_token.length = $4.length + 1;
char *copy = copy_name ($3);
error (_("No type \"%s\" within class "
"or namespace \"%s\"."),
- copy, TYPE_NAME ($1.type));
+ copy, TYPE_SAFE_NAME ($1.type));
}
;
if (parse_completion && *lexptr == '\0')
saw_name_at_eof = 1;
+
+ yylval.ssym.stoken = yylval.sval;
+ yylval.ssym.sym = NULL;
+ yylval.ssym.is_a_field_of_this = 0;
return NAME;
}
yylval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
return FILENAME;
}
+
+ /* If we found a field of 'this', we might have erroneously
+ found a constructor where we wanted a type name. Handle this
+ case by noticing that we found a constructor and then look up
+ the type tag instead. */
+ if (is_a_field_of_this.type != NULL
+ && is_a_field_of_this.fn_field != NULL
+ && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields,
+ 0))
+ {
+ struct field_of_this_result inner_is_a_field_of_this;
+
+ sym = lookup_symbol (copy, block, STRUCT_DOMAIN,
+ &inner_is_a_field_of_this);
+ if (sym != NULL)
+ {
+ yylval.tsym.type = SYMBOL_TYPE (sym);
+ return TYPENAME;
+ }
+ }
}
if (sym && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
}
/* Like classify_name, but used by the inner loop of the lexer, when a
- name might have already been seen. FIRST_NAME is true if the token
- in `yylval' is the first component of a name, false otherwise. */
+ name might have already been seen. CONTEXT is the context type, or
+ NULL if this is the first component of a name. */
static int
-classify_inner_name (const struct block *block, int first_name)
+classify_inner_name (const struct block *block, struct type *context)
{
- struct type *type, *new_type;
+ struct type *type;
char *copy;
- if (first_name)
+ if (context == NULL)
return classify_name (block);
- type = check_typedef (yylval.tsym.type);
+ type = check_typedef (context);
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION
&& TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
return ERROR;
- copy = copy_name (yylval.tsym.stoken);
- yylval.ssym.sym = cp_lookup_nested_symbol (yylval.tsym.type, copy, block);
+ copy = copy_name (yylval.ssym.stoken);
+ yylval.ssym.sym = cp_lookup_nested_symbol (type, copy, block);
if (yylval.ssym.sym == NULL)
return ERROR;
return TYPENAME;
default:
- yylval.ssym.is_a_field_of_this = 0;
return NAME;
}
internal_error (__FILE__, __LINE__, _("not reached"));
{
token_and_value current;
int first_was_coloncolon, last_was_coloncolon, first_iter;
+ struct type *context_type = NULL;
if (popping && !VEC_empty (token_and_value, token_fifo))
{
last_was_coloncolon = first_was_coloncolon;
obstack_free (&name_obstack, obstack_base (&name_obstack));
if (!last_was_coloncolon)
- obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
+ {
+ obstack_grow (&name_obstack, yylval.sval.ptr, yylval.sval.length);
+ context_type = yylval.tsym.type;
+ }
current.value = yylval;
first_iter = 1;
while (1)
classification = classify_inner_name (first_was_coloncolon
? NULL
: expression_context_block,
- first_iter);
+ context_type);
/* We keep going until we either run out of names, or until
we have a qualified name which is not a type. */
if (classification != TYPENAME && classification != NAME)
}
/* Update the partial name we are constructing. */
- if (!first_iter)
+ if (context_type != NULL)
{
/* We don't want to put a leading "::" into the name. */
obstack_grow_str (&name_obstack, "::");
current.token = classification;
last_was_coloncolon = 0;
+
+ if (classification == NAME)
+ break;
+
+ context_type = yylval.tsym.type;
}
else if (next.token == COLONCOLON && !last_was_coloncolon)
last_was_coloncolon = 1;