-/* If NAME is a type name in this scope, return it. */
-
-static struct type *
-d_type_from_name (struct stoken name)
-{
- struct symbol *sym;
- char *copy = copy_name (name);
-
- sym = lookup_symbol (copy, expression_context_block,
- STRUCT_DOMAIN, NULL).symbol;
- if (sym != NULL)
- return SYMBOL_TYPE (sym);
-
- return NULL;
-}
-
-/* If NAME is a module name in this scope, return it. */
-
-static struct type *
-d_module_from_name (struct stoken name)
-{
- struct symbol *sym;
- char *copy = copy_name (name);
-
- sym = lookup_symbol (copy, expression_context_block,
- MODULE_DOMAIN, NULL).symbol;
- if (sym != NULL)
- return SYMBOL_TYPE (sym);
-
- return NULL;
-}
-
-/* If NAME is a valid variable name in this scope, push it and return 1.
- Otherwise, return 0. */
-
-static int
-push_variable (struct parser_state *ps, struct stoken name)
-{
- char *copy = copy_name (name);
- struct field_of_this_result is_a_field_of_this;
- struct block_symbol sym
- = lookup_symbol (copy, expression_context_block, VAR_DOMAIN,
- &is_a_field_of_this);
-
- if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
- {
- if (symbol_read_needs_frame (sym.symbol))
- {
- if (innermost_block == 0 ||
- contained_in (sym.block, innermost_block))
- innermost_block = sym.block;
- }
-
- write_exp_elt_opcode (ps, OP_VAR_VALUE);
- /* We want to use the selected frame, not another more inner frame
- which happens to be in the same block. */
- write_exp_elt_block (ps, NULL);
- write_exp_elt_sym (ps, sym.symbol);
- write_exp_elt_opcode (ps, OP_VAR_VALUE);
- return 1;
- }
- if (is_a_field_of_this.type != NULL)
- {
- /* It hangs off of `this'. Must not inadvertently convert from a
- method call to data ref. */
- if (innermost_block == 0 ||
- contained_in (sym.block, innermost_block))
- innermost_block = sym.block;
- write_exp_elt_opcode (ps, OP_THIS);
- write_exp_elt_opcode (ps, OP_THIS);
- write_exp_elt_opcode (ps, STRUCTOP_PTR);
- write_exp_string (ps, name);
- write_exp_elt_opcode (ps, STRUCTOP_PTR);
- return 1;
- }
- return 0;
-}
-
-/* Assuming a reference expression has been pushed, emit the
- STRUCTOP_PTR ops to access the field named NAME. If NAME is a
- qualified name (has '.'), generate a field access for each part. */
-
-static void
-push_fieldnames (struct parser_state *ps, struct stoken name)
-{
- int i;
- struct stoken token;
- token.ptr = name.ptr;
- for (i = 0; ; i++)
- {
- if (i == name.length || name.ptr[i] == '.')
- {
- /* token.ptr is start of current field name. */
- token.length = &name.ptr[i] - token.ptr;
- write_exp_elt_opcode (ps, STRUCTOP_PTR);
- write_exp_string (ps, token);
- write_exp_elt_opcode (ps, STRUCTOP_PTR);
- token.ptr += token.length + 1;
- }
- if (i >= name.length)
- break;
- }
-}
-
-/* Helper routine for push_expression_name. Handle a TYPE symbol,
- where DOT_INDEX is the index of the first '.' if NAME is part of
- a qualified type. */
-
-static void
-push_type_name (struct parser_state *ps, struct type *type,
- struct stoken name, int dot_index)
-{
- if (dot_index == name.length)
- {
- write_exp_elt_opcode (ps, OP_TYPE);
- write_exp_elt_type (ps, type);
- write_exp_elt_opcode (ps, OP_TYPE);
- }
- else
- {
- struct stoken token;
-
- token.ptr = name.ptr;
- token.length = dot_index;
-
- dot_index = 0;
-
- while (dot_index < name.length && name.ptr[dot_index] != '.')
- dot_index++;
- token.ptr = name.ptr;
- token.length = dot_index;
-
- write_exp_elt_opcode (ps, OP_SCOPE);
- write_exp_elt_type (ps, type);
- write_exp_string (ps, token);
- write_exp_elt_opcode (ps, OP_SCOPE);
-
- if (dot_index < name.length)
- {
- dot_index++;
- name.ptr += dot_index;
- name.length -= dot_index;
- push_fieldnames (ps, name);
- }
- }
-}
-
-/* Helper routine for push_expression_name. Like push_type_name,
- but used when TYPE is a module. Returns 1 on pushing the symbol. */
-
-static int
-push_module_name (struct parser_state *ps, struct type *module,
- struct stoken name, int dot_index)
-{
- if (dot_index == name.length)
- {
- write_exp_elt_opcode (ps, OP_TYPE);
- write_exp_elt_type (ps, module);
- write_exp_elt_opcode (ps, OP_TYPE);
- return 1;
- }
- else
- {
- struct symbol *sym;
- char *copy;
-
- copy = copy_name (name);
- sym = lookup_symbol_in_static_block (copy, expression_context_block,
- VAR_DOMAIN).symbol;
- if (sym != NULL)
- sym = lookup_global_symbol (copy, expression_context_block,
- VAR_DOMAIN).symbol;
-
- if (sym != NULL)
- {
- if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
- {
- write_exp_elt_opcode (ps, OP_VAR_VALUE);
- write_exp_elt_block (ps, NULL);
- write_exp_elt_sym (ps, sym);
- write_exp_elt_opcode (ps, OP_VAR_VALUE);
- }
- else
- {
- write_exp_elt_opcode (ps, OP_TYPE);
- write_exp_elt_type (ps, SYMBOL_TYPE (sym));
- write_exp_elt_opcode (ps, OP_TYPE);
- }
- return 1;
- }
- }
-
- return 0;
-}
-
-/* Handle NAME in an expression (or LHS), which could be a
- variable, type, or module. */
-
-static void
-push_expression_name (struct parser_state *ps, struct stoken name)
-{
- struct stoken token;
- struct type *typ;
- struct bound_minimal_symbol msymbol;
- char *copy;
- int doti;
-
- /* Handle VAR, which could be local or global. */
- if (push_variable (ps, name) != 0)
- return;
-
- /* Handle MODULE. */
- typ = d_module_from_name (name);
- if (typ != NULL)
- {
- if (push_module_name (ps, typ, name, name.length) != 0)
- return;
- }
-
- /* Handle TYPE. */
- typ = d_type_from_name (name);
- if (typ != NULL)
- {
- push_type_name (ps, typ, name, name.length);
- return;
- }
-
- /* Handle VAR.FIELD1..FIELDN. */
- for (doti = 0; doti < name.length; doti++)
- {
- if (name.ptr[doti] == '.')
- {
- token.ptr = name.ptr;
- token.length = doti;
-
- if (push_variable (ps, token) != 0)
- {
- token.ptr = name.ptr + doti + 1;
- token.length = name.length - doti - 1;
- push_fieldnames (ps, token);
- return;
- }
- break;
- }
- }
-
- /* Continue looking if we found a '.' in the name. */
- if (doti < name.length)
- {
- token.ptr = name.ptr;
- for (;;)
- {
- token.length = doti;
-
- /* Handle PACKAGE.MODULE. */
- typ = d_module_from_name (token);
- if (typ != NULL)
- {
- if (push_module_name (ps, typ, name, doti) != 0)
- return;
- }
- /* Handle TYPE.FIELD1..FIELDN. */
- typ = d_type_from_name (token);
- if (typ != NULL)
- {
- push_type_name (ps, typ, name, doti);
- return;
- }
-
- if (doti >= name.length)
- break;
- doti++; /* Skip '.' */
- while (doti < name.length && name.ptr[doti] != '.')
- doti++;
- }
- }
-
- /* Lookup foreign name in global static symbols. */
- copy = copy_name (name);
- msymbol = lookup_bound_minimal_symbol (copy);
- if (msymbol.minsym != NULL)
- write_exp_msymbol (ps, msymbol);
- else 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);
-}
-