+static struct candidate *
+ideal_candidate (candidates, n_candidates, len)
+ struct candidate *candidates;
+ int n_candidates;
+ int len;
+{
+ struct candidate *cp = candidates+n_candidates;
+ int i, j = -1, best_code;
+
+ /* For each argument, sort the functions from best to worst for the arg.
+ For each function that's not best for this arg, set its overall
+ harshness to EVIL so that other args won't like it. The candidate
+ list for the last argument is the intersection of all the best-liked
+ functions. */
+
+ qsort (candidates, n_candidates, sizeof (struct candidate),
+ rank_for_overload);
+ best_code = cp[-1].h.code;
+
+ /* If they're at least as good as each other, do an arg-by-arg check. */
+ if (! strictly_better (cp[-1].h.code, cp[-2].h.code))
+ {
+ int better = 0;
+ int worse = 0;
+
+ for (j = 0; j < n_candidates; j++)
+ if (! strictly_better (candidates[j].h.code, best_code))
+ break;
+
+ qsort (candidates+j, n_candidates-j, sizeof (struct candidate),
+ rank_for_ideal);
+ for (i = 0; i < len; i++)
+ {
+ if (cp[-1].harshness[i].code < cp[-2].harshness[i].code)
+ better = 1;
+ else if (cp[-1].harshness[i].code > cp[-2].harshness[i].code)
+ worse = 1;
+ else if (cp[-1].harshness[i].code & STD_CODE)
+ {
+ /* If it involves a standard conversion, let the
+ inheritance lattice be the final arbiter. */
+ if (cp[-1].harshness[i].distance > cp[-2].harshness[i].distance)
+ worse = 1;
+ else if (cp[-1].harshness[i].distance < cp[-2].harshness[i].distance)
+ better = 1;
+ }
+ else if (cp[-1].harshness[i].code & PROMO_CODE)
+ {
+ /* For integral promotions, take into account a finer
+ granularity for determining which types should be favored
+ over others in such promotions. */
+ if (cp[-1].harshness[i].int_penalty > cp[-2].harshness[i].int_penalty)
+ worse = 1;
+ else if (cp[-1].harshness[i].int_penalty < cp[-2].harshness[i].int_penalty)
+ better = 1;
+ }
+ }
+
+ if (! better || worse)
+ return NULL;
+ }
+ return cp-1;
+}
+
+/* Assume that if the class referred to is not in the
+ current class hierarchy, that it may be remote.
+ PARENT is assumed to be of aggregate type here. */
+
+static int
+may_be_remote (parent)
+ tree parent;
+{
+ if (TYPE_OVERLOADS_METHOD_CALL_EXPR (parent) == 0)
+ return 0;
+
+ if (current_class_type == NULL_TREE)
+ return 0;
+
+ if (parent == current_class_type)
+ return 0;
+
+ if (UNIQUELY_DERIVED_FROM_P (parent, current_class_type))
+ return 0;
+ return 1;
+}
+
+tree
+build_vfield_ref (datum, type)
+ tree datum, type;
+{
+ tree rval;
+ int old_assume_nonnull_objects = flag_assume_nonnull_objects;
+
+ if (datum == error_mark_node)
+ return error_mark_node;
+
+ /* Vtable references are always made from non-null objects. */
+ flag_assume_nonnull_objects = 1;
+ if (TREE_CODE (TREE_TYPE (datum)) == REFERENCE_TYPE)
+ datum = convert_from_reference (datum);
+
+ if (! TYPE_USES_COMPLEX_INHERITANCE (type))
+ rval = build (COMPONENT_REF, TREE_TYPE (CLASSTYPE_VFIELD (type)),
+ datum, CLASSTYPE_VFIELD (type));
+ else
+ rval = build_component_ref (datum, DECL_NAME (CLASSTYPE_VFIELD (type)), NULL_TREE, 0);
+ flag_assume_nonnull_objects = old_assume_nonnull_objects;
+
+ return rval;
+}
+
+/* Build a call to a member of an object. I.e., one that overloads
+ operator ()(), or is a pointer-to-function or pointer-to-method. */
+
+static tree
+build_field_call (basetype_path, instance_ptr, name, parms)
+ tree basetype_path, instance_ptr, name, parms;
+{
+ tree field, instance;
+
+ if (instance_ptr == current_class_ptr)
+ {
+ /* Check to see if we really have a reference to an instance variable
+ with `operator()()' overloaded. */
+ field = IDENTIFIER_CLASS_VALUE (name);
+
+ if (field == NULL_TREE)
+ {
+ cp_error ("`this' has no member named `%D'", name);
+ return error_mark_node;
+ }
+
+ if (TREE_CODE (field) == FIELD_DECL)
+ {
+ /* If it's a field, try overloading operator (),
+ or calling if the field is a pointer-to-function. */
+ instance = build_component_ref_1 (current_class_ref, field, 0);
+ if (instance == error_mark_node)
+ return error_mark_node;
+
+ if (TYPE_LANG_SPECIFIC (TREE_TYPE (instance))
+ && (TYPE_OVERLOADS_CALL_EXPR (TREE_TYPE (instance))
+ || flag_ansi_overloading))
+ return build_opfncall (CALL_EXPR, LOOKUP_NORMAL, instance, parms, NULL_TREE);
+
+ if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE)
+ {
+ if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == FUNCTION_TYPE)
+ return build_function_call (instance, parms);
+ else if (TREE_CODE (TREE_TYPE (TREE_TYPE (instance))) == METHOD_TYPE)
+ return build_function_call (instance, tree_cons (NULL_TREE, current_class_ptr, parms));
+ }
+ }
+ return NULL_TREE;
+ }
+
+ /* Check to see if this is not really a reference to an instance variable
+ with `operator()()' overloaded. */
+ field = lookup_field (basetype_path, name, 1, 0);
+
+ /* This can happen if the reference was ambiguous or for access
+ violations. */
+ if (field == error_mark_node)
+ return error_mark_node;
+
+ if (field)
+ {
+ tree basetype;
+ tree ftype = TREE_TYPE (field);
+
+ if (TREE_CODE (ftype) == REFERENCE_TYPE)
+ ftype = TREE_TYPE (ftype);
+
+ if (TYPE_LANG_SPECIFIC (ftype)
+ && (TYPE_OVERLOADS_CALL_EXPR (ftype) || flag_ansi_overloading))
+ {
+ /* Make the next search for this field very short. */
+ basetype = DECL_FIELD_CONTEXT (field);
+ instance_ptr = convert_pointer_to (basetype, instance_ptr);
+
+ instance = build_indirect_ref (instance_ptr, NULL_PTR);
+ return build_opfncall (CALL_EXPR, LOOKUP_NORMAL,
+ build_component_ref_1 (instance, field, 0),
+ parms, NULL_TREE);
+ }
+ if (TREE_CODE (ftype) == POINTER_TYPE)
+ {
+ if (TREE_CODE (TREE_TYPE (ftype)) == FUNCTION_TYPE
+ || TREE_CODE (TREE_TYPE (ftype)) == METHOD_TYPE)
+ {
+ /* This is a member which is a pointer to function. */
+ tree ref
+ = build_component_ref_1 (build_indirect_ref (instance_ptr,
+ NULL_PTR),
+ field, LOOKUP_COMPLAIN);
+ if (ref == error_mark_node)
+ return error_mark_node;
+ return build_function_call (ref, parms);
+ }
+ }
+ else if (TREE_CODE (ftype) == METHOD_TYPE)
+ {
+ error ("invalid call via pointer-to-member function");
+ return error_mark_node;
+ }
+ else
+ return NULL_TREE;
+ }
+ return NULL_TREE;
+}
+
+tree
+find_scoped_type (type, inner_name, inner_types)
+ tree type, inner_name, inner_types;
+{
+ tree tags = CLASSTYPE_TAGS (type);
+
+ while (tags)
+ {
+ /* The TREE_PURPOSE of an enum tag (which becomes a member of the
+ enclosing class) is set to the name for the enum type. So, if
+ inner_name is `bar', and we strike `baz' for `enum bar { baz }',
+ then this test will be true. */
+ if (TREE_PURPOSE (tags) == inner_name)
+ {
+ if (inner_types == NULL_TREE)
+ return TYPE_NAME (TREE_VALUE (tags));
+ return resolve_scope_to_name (TREE_VALUE (tags), inner_types);
+ }
+ tags = TREE_CHAIN (tags);
+ }
+
+ /* Look for a TYPE_DECL. */
+ for (tags = TYPE_FIELDS (type); tags; tags = TREE_CHAIN (tags))
+ if (TREE_CODE (tags) == TYPE_DECL && DECL_NAME (tags) == inner_name)
+ {
+ /* Code by raeburn. */
+ if (inner_types == NULL_TREE)
+ return tags;
+ return resolve_scope_to_name (TREE_TYPE (tags), inner_types);
+ }
+
+ return NULL_TREE;
+}
+
+/* Resolve an expression NAME1::NAME2::...::NAMEn to
+ the name that names the above nested type. INNER_TYPES
+ is a chain of nested type names (held together by SCOPE_REFs);
+ OUTER_TYPE is the type we know to enclose INNER_TYPES.
+ Returns NULL_TREE if there is an error. */
+
+tree
+resolve_scope_to_name (outer_type, inner_stuff)
+ tree outer_type, inner_stuff;
+{
+ register tree tmp;
+ tree inner_name, inner_type;
+
+ if (outer_type == NULL_TREE && current_class_type != NULL_TREE)
+ {
+ /* We first try to look for a nesting in our current class context,
+ then try any enclosing classes. */
+ tree type = current_class_type;
+
+ while (type && (TREE_CODE (type) == RECORD_TYPE
+ || TREE_CODE (type) == UNION_TYPE))
+ {
+ tree rval = resolve_scope_to_name (type, inner_stuff);
+
+ if (rval != NULL_TREE)
+ return rval;
+ type = DECL_CONTEXT (TYPE_NAME (type));
+ }
+ }
+
+ if (TREE_CODE (inner_stuff) == SCOPE_REF)
+ {
+ inner_name = TREE_OPERAND (inner_stuff, 0);
+ inner_type = TREE_OPERAND (inner_stuff, 1);
+ }
+ else
+ {
+ inner_name = inner_stuff;
+ inner_type = NULL_TREE;
+ }
+
+ if (outer_type == NULL_TREE)
+ {
+ tree x;
+ /* If we have something that's already a type by itself,
+ use that. */
+ if (IDENTIFIER_HAS_TYPE_VALUE (inner_name))
+ {
+ if (inner_type)
+ return resolve_scope_to_name (IDENTIFIER_TYPE_VALUE (inner_name),
+ inner_type);
+ return inner_name;
+ }
+
+ x = lookup_name (inner_name, 0);
+
+ if (x && TREE_CODE (x) == NAMESPACE_DECL)
+ {
+ x = lookup_namespace_name (x, inner_type);
+ return x;
+ }
+ return NULL_TREE;
+ }
+
+ if (! IS_AGGR_TYPE (outer_type))
+ return NULL_TREE;
+
+ /* Look for member classes or enums. */
+ tmp = find_scoped_type (outer_type, inner_name, inner_type);
+
+ /* If it's not a type in this class, then go down into the
+ base classes and search there. */
+ if (! tmp && TYPE_BINFO (outer_type))
+ {
+ tree binfos = TYPE_BINFO_BASETYPES (outer_type);
+ int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
+
+ for (i = 0; i < n_baselinks; i++)
+ {
+ tree base_binfo = TREE_VEC_ELT (binfos, i);
+ tmp = resolve_scope_to_name (BINFO_TYPE (base_binfo), inner_stuff);
+ if (tmp)
+ return tmp;
+ }
+ tmp = NULL_TREE;
+ }
+
+ return tmp;
+}
+
+/* Build a method call of the form `EXP->SCOPES::NAME (PARMS)'.
+ This is how virtual function calls are avoided. */
+
+tree
+build_scoped_method_call (exp, basetype, name, parms)
+ tree exp, basetype, name, parms;
+{
+ /* Because this syntactic form does not allow
+ a pointer to a base class to be `stolen',
+ we need not protect the derived->base conversion
+ that happens here.
+
+ @@ But we do have to check access privileges later. */
+ tree binfo, decl;
+ tree type = TREE_TYPE (exp);
+
+ if (type == error_mark_node
+ || basetype == error_mark_node)
+ return error_mark_node;
+
+ if (processing_template_decl)
+ {
+ if (TREE_CODE (name) == BIT_NOT_EXPR)
+ {
+ tree type = get_aggr_from_typedef (TREE_OPERAND (name, 0), 1);
+ name = build_min_nt (BIT_NOT_EXPR, type);
+ }
+ name = build_min_nt (SCOPE_REF, basetype, name);
+ return build_min_nt (METHOD_CALL_EXPR, name, exp, parms, NULL_TREE);
+ }
+
+ if (TREE_CODE (type) == REFERENCE_TYPE)
+ type = TREE_TYPE (type);
+
+ /* Destructors can be "called" for simple types; see 5.2.4 and 12.4 Note
+ that explicit ~int is caught in the parser; this deals with typedefs
+ and template parms. */
+ if (TREE_CODE (name) == BIT_NOT_EXPR && ! IS_AGGR_TYPE (basetype))
+ {
+ if (type != basetype)
+ cp_error ("type of `%E' does not match destructor type `%T' (type was `%T')",
+ exp, basetype, type);
+ name = TREE_OPERAND (name, 0);
+ if (basetype != name && basetype != get_type_value (name))
+ cp_error ("qualified type `%T' does not match destructor name `~%T'",
+ basetype, name);
+ return convert (void_type_node, exp);
+ }
+
+ if (! is_aggr_type (basetype, 1))
+ return error_mark_node;
+
+ if (! IS_AGGR_TYPE (type))
+ {
+ cp_error ("base object `%E' of scoped method call is of non-aggregate type `%T'",
+ exp, type);
+ return error_mark_node;
+ }
+
+ if ((binfo = binfo_or_else (basetype, type)))
+ {
+ if (binfo == error_mark_node)
+ return error_mark_node;
+ if (TREE_CODE (exp) == INDIRECT_REF)
+ decl = build_indirect_ref (convert_pointer_to (binfo,
+ build_unary_op (ADDR_EXPR, exp, 0)), NULL_PTR);
+ else
+ decl = build_scoped_ref (exp, basetype);
+
+ /* Call to a destructor. */
+ if (TREE_CODE (name) == BIT_NOT_EXPR)
+ {
+ /* Explicit call to destructor. */
+ name = TREE_OPERAND (name, 0);
+ if (! (name == TYPE_MAIN_VARIANT (TREE_TYPE (decl))
+ || name == constructor_name (TREE_TYPE (decl))
+ || TREE_TYPE (decl) == get_type_value (name)))
+ {
+ cp_error
+ ("qualified type `%T' does not match destructor name `~%T'",
+ TREE_TYPE (decl), name);
+ return error_mark_node;
+ }
+ if (! TYPE_HAS_DESTRUCTOR (TREE_TYPE (decl)))
+ return convert (void_type_node, exp);
+
+ return build_delete (TREE_TYPE (decl), decl, integer_two_node,
+ LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR,
+ 0);
+ }
+
+ /* Call to a method. */
+ return build_method_call (decl, name, parms, binfo,
+ LOOKUP_NORMAL|LOOKUP_NONVIRTUAL);
+ }
+ return error_mark_node;
+}
+
+static void
+print_candidates (candidates)
+ tree candidates;
+{
+ cp_error_at ("candidates are: %D", TREE_VALUE (candidates));
+ candidates = TREE_CHAIN (candidates);
+
+ while (candidates)
+ {
+ cp_error_at (" %D", TREE_VALUE (candidates));
+ candidates = TREE_CHAIN (candidates);
+ }
+}
+
+static void
+print_n_candidates (candidates, n)
+ struct candidate *candidates;
+ int n;
+{
+ int i;
+
+ cp_error_at ("candidates are: %D", candidates[0].function);
+ for (i = 1; i < n; i++)
+ cp_error_at (" %D", candidates[i].function);
+}
+
+/* We want the address of a function or method. We avoid creating a
+ pointer-to-member function. */
+
+tree
+build_addr_func (function)
+ tree function;
+{
+ tree type = TREE_TYPE (function);
+
+ /* We have to do these by hand to avoid real pointer to member
+ functions. */
+ if (TREE_CODE (type) == METHOD_TYPE)
+ {
+ tree addr;
+
+ type = build_pointer_type (type);
+
+ if (mark_addressable (function) == 0)
+ return error_mark_node;
+
+ addr = build1 (ADDR_EXPR, type, function);
+
+ /* Address of a static or external variable or function counts
+ as a constant */
+ if (staticp (function))
+ TREE_CONSTANT (addr) = 1;
+
+ function = addr;
+ }
+ else
+ function = default_conversion (function);
+
+ return function;
+}
+
+/* Build a CALL_EXPR, we can handle FUNCTION_TYPEs, METHOD_TYPEs, or
+ POINTER_TYPE to those. Note, pointer to member function types
+ (TYPE_PTRMEMFUNC_P) must be handled by our callers. */
+
+tree
+build_call (function, result_type, parms)
+ tree function, result_type, parms;
+{
+ int is_constructor = 0;
+
+ function = build_addr_func (function);
+
+ if (TYPE_PTRMEMFUNC_P (TREE_TYPE (function)))
+ {
+ sorry ("unable to call pointer to member function here");
+ return error_mark_node;
+ }
+
+ if (TREE_CODE (function) == ADDR_EXPR
+ && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
+ && DECL_CONSTRUCTOR_P (TREE_OPERAND (function, 0)))
+ is_constructor = 1;
+
+ function = build_nt (CALL_EXPR, function, parms, NULL_TREE);
+ TREE_HAS_CONSTRUCTOR (function) = is_constructor;
+ TREE_TYPE (function) = result_type;
+ TREE_SIDE_EFFECTS (function) = 1;
+
+ return function;
+}
+
+static tree
+default_parm_conversions (parms, last)
+ tree parms, *last;
+{
+ tree parm, parmtypes = NULL_TREE;
+
+ *last = NULL_TREE;
+
+ for (parm = parms; parm; parm = TREE_CHAIN (parm))
+ {
+ tree t = TREE_TYPE (TREE_VALUE (parm));
+
+ if (TREE_CODE (t) == OFFSET_TYPE
+ || TREE_CODE (t) == METHOD_TYPE
+ || TREE_CODE (t) == FUNCTION_TYPE)
+ {
+ TREE_VALUE (parm) = default_conversion (TREE_VALUE (parm));
+ t = TREE_TYPE (TREE_VALUE (parm));
+ }
+
+ if (t == error_mark_node)
+ return error_mark_node;
+
+ *last = build_tree_list (NULL_TREE, t);
+ parmtypes = chainon (parmtypes, *last);
+ }
+
+ return parmtypes;
+}
+
+
+/* Build something of the form ptr->method (args)
+ or object.method (args). This can also build
+ calls to constructors, and find friends.
+
+ Member functions always take their class variable
+ as a pointer.
+
+ INSTANCE is a class instance.
+
+ NAME is the name of the method desired, usually an IDENTIFIER_NODE.
+
+ PARMS help to figure out what that NAME really refers to.
+
+ BASETYPE_PATH, if non-NULL, contains a chain from the type of INSTANCE
+ down to the real instance type to use for access checking. We need this
+ information to get protected accesses correct. This parameter is used
+ by build_member_call.
+
+ FLAGS is the logical disjunction of zero or more LOOKUP_
+ flags. See cp-tree.h for more info.
+
+ If this is all OK, calls build_function_call with the resolved
+ member function.
+
+ This function must also handle being called to perform
+ initialization, promotion/coercion of arguments, and
+ instantiation of default parameters.
+
+ Note that NAME may refer to an instance variable name. If
+ `operator()()' is defined for the type of that field, then we return
+ that result. */
+
+tree
+build_method_call (instance, name, parms, basetype_path, flags)
+ tree instance, name, parms, basetype_path;
+ int flags;
+{
+ register tree function, fntype, value_type;
+ register tree basetype, save_basetype;
+ register tree baselink, result, parmtypes, parm;
+ tree last;
+ int pass;
+ tree access = access_public_node;
+ tree orig_basetype = basetype_path ? BINFO_TYPE (basetype_path) : NULL_TREE;
+
+ /* Range of cases for vtable optimization. */
+ enum vtable_needs { not_needed, maybe_needed, unneeded, needed };
+ enum vtable_needs need_vtbl = not_needed;
+
+ char *name_kind;
+ tree save_name = name;
+ int ever_seen = 0;
+ tree instance_ptr = NULL_TREE;
+ int all_virtual = flag_all_virtual;
+ int static_call_context = 0;
+ tree found_fns = NULL_TREE;
+
+ /* Keep track of `const' and `volatile' objects. */
+ int constp, volatilep;
+
+#ifdef GATHER_STATISTICS
+ n_build_method_call++;
+#endif
+
+ if (instance == error_mark_node
+ || name == error_mark_node
+ || parms == error_mark_node
+ || (instance != NULL_TREE && TREE_TYPE (instance) == error_mark_node))
+ return error_mark_node;
+
+ if (processing_template_decl)
+ {
+ if (TREE_CODE (name) == BIT_NOT_EXPR)
+ {
+ tree type = get_aggr_from_typedef (TREE_OPERAND (name, 0), 1);
+ name = build_min_nt (BIT_NOT_EXPR, type);
+ }
+
+ return build_min_nt (METHOD_CALL_EXPR, name, instance, parms, NULL_TREE);
+ }
+
+ /* This is the logic that magically deletes the second argument to
+ operator delete, if it is not needed. */
+ if (name == ansi_opname[(int) DELETE_EXPR] && list_length (parms)==2)
+ {
+ tree save_last = TREE_CHAIN (parms);
+ tree result;
+ /* get rid of unneeded argument */
+ TREE_CHAIN (parms) = NULL_TREE;
+ result = build_method_call (instance, name, parms, basetype_path,
+ (LOOKUP_SPECULATIVELY|flags)
+ &~LOOKUP_COMPLAIN);
+ /* If it finds a match, return it. */
+ if (result)
+ return build_method_call (instance, name, parms, basetype_path, flags);
+ /* If it doesn't work, two argument delete must work */
+ TREE_CHAIN (parms) = save_last;
+ }
+ /* We already know whether it's needed or not for vec delete. */
+ else if (name == ansi_opname[(int) VEC_DELETE_EXPR]
+ && TYPE_LANG_SPECIFIC (TREE_TYPE (instance))
+ && ! TYPE_VEC_DELETE_TAKES_SIZE (TREE_TYPE (instance)))
+ TREE_CHAIN (parms) = NULL_TREE;
+
+ if (TREE_CODE (name) == BIT_NOT_EXPR)
+ {
+ flags |= LOOKUP_DESTRUCTOR;
+ name = TREE_OPERAND (name, 0);
+ if (parms)
+ error ("destructors take no parameters");
+ basetype = TREE_TYPE (instance);
+ if (TREE_CODE (basetype) == REFERENCE_TYPE)
+ basetype = TREE_TYPE (basetype);
+ if (! (name == basetype
+ || (IS_AGGR_TYPE (basetype)
+ && name == constructor_name (basetype))
+ || basetype == get_type_value (name)))
+ {
+ cp_error ("destructor name `~%D' does not match type `%T' of expression",
+ name, basetype);
+ return convert (void_type_node, instance);
+ }
+
+ if (! TYPE_HAS_DESTRUCTOR (basetype))
+ return convert (void_type_node, instance);
+ instance = default_conversion (instance);
+ instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
+ return build_delete (build_pointer_type (basetype),
+ instance_ptr, integer_two_node,
+ LOOKUP_NORMAL|LOOKUP_DESTRUCTOR, 0);
+ }
+
+ if (flag_ansi_overloading)
+ return build_new_method_call (instance, name, parms, basetype_path, flags);
+
+ {
+ char *xref_name;
+
+ /* Initialize name for error reporting. */
+ if (IDENTIFIER_OPNAME_P (name) && ! IDENTIFIER_TYPENAME_P (name))
+ {
+ char *p = operator_name_string (name);
+ xref_name = (char *)alloca (strlen (p) + 10);
+ sprintf (xref_name, "operator %s", p);
+ }
+ else if (TREE_CODE (name) == SCOPE_REF)
+ xref_name = IDENTIFIER_POINTER (TREE_OPERAND (name, 1));
+ else
+ xref_name = IDENTIFIER_POINTER (name);
+
+ GNU_xref_call (current_function_decl, xref_name);
+ }
+
+ if (instance == NULL_TREE)
+ {
+ basetype = NULL_TREE;
+ /* Check cases where this is really a call to raise
+ an exception. */
+ if (current_class_type && TREE_CODE (name) == IDENTIFIER_NODE)
+ {
+ basetype = purpose_member (name, CLASSTYPE_TAGS (current_class_type));
+ if (basetype)
+ basetype = TREE_VALUE (basetype);
+ }
+ else if (TREE_CODE (name) == SCOPE_REF
+ && TREE_CODE (TREE_OPERAND (name, 0)) == IDENTIFIER_NODE)
+ {
+ if (! is_aggr_typedef (TREE_OPERAND (name, 0), 1))
+ return error_mark_node;
+ basetype = purpose_member (TREE_OPERAND (name, 1),
+ CLASSTYPE_TAGS (IDENTIFIER_TYPE_VALUE (TREE_OPERAND (name, 0))));
+ if (basetype)
+ basetype = TREE_VALUE (basetype);
+ }
+
+ if (basetype != NULL_TREE)
+ ;
+ /* call to a constructor... */
+ else if (basetype_path)
+ {
+ basetype = BINFO_TYPE (basetype_path);
+ if (name == TYPE_IDENTIFIER (basetype))
+ name = ctor_identifier;
+ }
+ else if (IDENTIFIER_HAS_TYPE_VALUE (name))
+ {
+ basetype = IDENTIFIER_TYPE_VALUE (name);
+ name = ctor_identifier;
+ }
+ else
+ {
+ tree typedef_name = lookup_name (name, 1);
+ if (typedef_name && TREE_CODE (typedef_name) == TYPE_DECL)
+ {
+ /* Canonicalize the typedef name. */
+ basetype = TREE_TYPE (typedef_name);
+ name = ctor_identifier;
+ }
+ else
+ {
+ cp_error ("no constructor named `%T' in scope",
+ name);
+ return error_mark_node;
+ }
+ }
+
+ if (! IS_AGGR_TYPE (basetype))
+ {
+ non_aggr_error:
+ if ((flags & LOOKUP_COMPLAIN) && TREE_CODE (basetype) != ERROR_MARK)
+ cp_error ("request for member `%D' in `%E', which is of non-aggregate type `%T'",
+ name, instance, basetype);
+
+ return error_mark_node;
+ }
+ }
+ else if (instance == current_class_ref || instance == current_class_ptr)
+ {
+ /* When doing initialization, we side-effect the TREE_TYPE of
+ current_class_ref, hence we cannot set up BASETYPE from CURRENT_CLASS_TYPE. */
+ basetype = TREE_TYPE (current_class_ref);
+
+ /* Anything manifestly `this' in constructors and destructors
+ has a known type, so virtual function tables are not needed. */
+ if (TYPE_VIRTUAL_P (basetype)
+ && !(flags & LOOKUP_NONVIRTUAL))
+ need_vtbl = (dtor_label || ctor_label)
+ ? unneeded : maybe_needed;
+
+ /* If `this' is a signature pointer and `name' is not a constructor,
+ we are calling a signature member function. In that case, set the
+ `basetype' to the signature type and dereference the `optr' field. */
+ if (IS_SIGNATURE_POINTER (basetype)
+ && TYPE_IDENTIFIER (basetype) != name)
+ {
+ basetype = SIGNATURE_TYPE (basetype);
+ instance_ptr = instance;
+ basetype_path = TYPE_BINFO (basetype);
+ }
+ else
+ {
+ instance = current_class_ref;
+ instance_ptr = current_class_ptr;
+ basetype_path = TYPE_BINFO (current_class_type);
+ }
+ result = build_field_call (basetype_path, instance_ptr, name, parms);
+
+ if (result)
+ return result;
+ }
+ else if (TREE_CODE (instance) == RESULT_DECL)
+ {
+ basetype = TREE_TYPE (instance);
+ /* Should we ever have to make a virtual function reference
+ from a RESULT_DECL, know that it must be of fixed type
+ within the scope of this function. */
+ if (!(flags & LOOKUP_NONVIRTUAL) && TYPE_VIRTUAL_P (basetype))
+ need_vtbl = maybe_needed;
+ instance_ptr = build1 (ADDR_EXPR, build_pointer_type (basetype), instance);
+ }
+ else
+ {
+ /* The MAIN_VARIANT of the type that `instance_ptr' winds up being. */
+ tree inst_ptr_basetype;
+
+ static_call_context =
+ (TREE_CODE (instance) == INDIRECT_REF
+ && TREE_CODE (TREE_OPERAND (instance, 0)) == NOP_EXPR
+ && TREE_OPERAND (TREE_OPERAND (instance, 0), 0) == error_mark_node);
+
+ if (TREE_CODE (instance) == OFFSET_REF)
+ instance = resolve_offset_ref (instance);
+
+ /* the base type of an instance variable is pointer to class */
+ basetype = TREE_TYPE (instance);
+
+ if (TREE_CODE (basetype) == REFERENCE_TYPE)
+ {
+ basetype = TREE_TYPE (basetype);
+ if (! IS_AGGR_TYPE (basetype))
+ goto non_aggr_error;
+ /* Call to convert not needed because we are remaining
+ within the same type. */
+ instance_ptr = build1 (NOP_EXPR, build_pointer_type (basetype),
+ instance);
+ inst_ptr_basetype = TYPE_MAIN_VARIANT (basetype);
+ }
+ else
+ {
+ if (! IS_AGGR_TYPE (basetype)
+ && ! (TYPE_LANG_SPECIFIC (basetype)
+ && (IS_SIGNATURE_POINTER (basetype)
+ || IS_SIGNATURE_REFERENCE (basetype))))
+ goto non_aggr_error;
+
+ /* If `instance' is a signature pointer/reference and `name' is
+ not a constructor, we are calling a signature member function.
+ In that case set the `basetype' to the signature type. */
+ if ((IS_SIGNATURE_POINTER (basetype)
+ || IS_SIGNATURE_REFERENCE (basetype))
+ && TYPE_IDENTIFIER (basetype) != name)
+ basetype = SIGNATURE_TYPE (basetype);
+
+ basetype = complete_type (basetype);
+
+ if ((IS_SIGNATURE (basetype)
+ && (instance_ptr = instance))
+ || (lvalue_p (instance)
+ && (instance_ptr = build_unary_op (ADDR_EXPR, instance, 0)))
+ || (instance_ptr = unary_complex_lvalue (ADDR_EXPR, instance)))
+ {
+ if (instance_ptr == error_mark_node)
+ return error_mark_node;
+ }
+ else if (TREE_CODE (instance) == NOP_EXPR
+ || TREE_CODE (instance) == CONSTRUCTOR)
+ {
+ /* A cast is not an lvalue. Initialize a fresh temp
+ with the value we are casting from, and proceed with
+ that temporary. We can't cast to a reference type,
+ so that simplifies the initialization to something
+ we can manage. */
+ tree temp = get_temp_name (TREE_TYPE (instance), 0);
+ if (IS_AGGR_TYPE (TREE_TYPE (instance)))
+ expand_aggr_init (temp, instance, 0, flags);
+ else
+ {
+ store_init_value (temp, instance);
+ expand_decl_init (temp);
+ }
+ instance = temp;
+ instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
+ }
+ else
+ {
+ if (TREE_CODE (instance) != CALL_EXPR)
+ my_friendly_abort (125);
+ if (TYPE_NEEDS_CONSTRUCTING (basetype))
+ instance = build_cplus_new (basetype, instance);
+ else
+ {
+ instance = get_temp_name (basetype, 0);
+ TREE_ADDRESSABLE (instance) = 1;
+ }
+ instance_ptr = build_unary_op (ADDR_EXPR, instance, 0);
+ }
+ /* @@ Should we call comp_target_types here? */
+ if (IS_SIGNATURE (basetype))
+ inst_ptr_basetype = basetype;
+ else
+ inst_ptr_basetype = TREE_TYPE (TREE_TYPE (instance_ptr));
+ if (TYPE_MAIN_VARIANT (basetype) == TYPE_MAIN_VARIANT (inst_ptr_basetype))
+ basetype = inst_ptr_basetype;
+ else
+ {
+ instance_ptr = convert (build_pointer_type (basetype), instance_ptr);
+ if (instance_ptr == error_mark_node)
+ return error_mark_node;
+ }
+ }
+
+ /* After converting `instance_ptr' above, `inst_ptr_basetype' was
+ not updated, so we use `basetype' instead. */
+ if (basetype_path == NULL_TREE
+ && IS_SIGNATURE (basetype))
+ basetype_path = TYPE_BINFO (basetype);
+ else if (basetype_path == NULL_TREE ||
+ BINFO_TYPE (basetype_path) != TYPE_MAIN_VARIANT (inst_ptr_basetype))
+ basetype_path = TYPE_BINFO (inst_ptr_basetype);
+
+ result = build_field_call (basetype_path, instance_ptr, name, parms);
+ if (result)
+ return result;
+
+ if (!(flags & LOOKUP_NONVIRTUAL) && TYPE_VIRTUAL_P (basetype))
+ {
+ if (TREE_SIDE_EFFECTS (instance_ptr))
+ {
+ /* This action is needed because the instance is needed
+ for providing the base of the virtual function table.
+ Without using a SAVE_EXPR, the function we are building
+ may be called twice, or side effects on the instance
+ variable (such as a post-increment), may happen twice. */
+ instance_ptr = save_expr (instance_ptr);
+ instance = build_indirect_ref (instance_ptr, NULL_PTR);
+ }
+ else if (TREE_CODE (TREE_TYPE (instance)) == POINTER_TYPE)
+ {
+ /* This happens when called for operator new (). */
+ instance = build_indirect_ref (instance, NULL_PTR);
+ }
+
+ need_vtbl = maybe_needed;
+ }
+ }
+
+ if (save_name == ctor_identifier)
+ save_name = TYPE_IDENTIFIER (basetype);
+
+ if (TYPE_SIZE (complete_type (basetype)) == 0)