diff --git a/gcc/tree.c b/gcc/tree.c index d38a87daf1f9..a12df1cb9f0d 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -3850,6 +3850,45 @@ build_function_type_list (tree return_type, ...) return args; } +/* Build a METHOD_TYPE for a member of BASETYPE. The RETTYPE (a TYPE) + and ARGTYPES (a TREE_LIST) are the return type and arguments types + for the method. An implicit additional parameter (of type + pointer-to-BASETYPE) is added to the ARGTYPES. */ + +tree +build_method_type_directly (tree basetype, + tree rettype, + tree argtypes) +{ + tree t; + tree ptype; + int hashcode; + + /* Make a node of the sort we want. */ + t = make_node (METHOD_TYPE); + + TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); + TREE_TYPE (t) = rettype; + ptype = build_pointer_type (basetype); + + /* The actual arglist for this function includes a "hidden" argument + which is "this". Put it into the list of argument types. */ + argtypes = tree_cons (NULL_TREE, ptype, argtypes); + TYPE_ARG_TYPES (t) = argtypes; + + /* If we already have such a type, use the old one and free this one. + Note that it also frees up the above cons cell if found. */ + hashcode = TYPE_HASH (basetype) + TYPE_HASH (rettype) + + type_hash_list (argtypes); + + t = type_hash_canon (hashcode, t); + + if (!COMPLETE_TYPE_P (t)) + layout_type (t); + + return t; +} + /* Construct, lay out and return the type of methods belonging to class BASETYPE and whose arguments and values are described by TYPE. If that type exists already, reuse it. @@ -3858,33 +3897,12 @@ build_function_type_list (tree return_type, ...) tree build_method_type (tree basetype, tree type) { - tree t; - unsigned int hashcode; - - /* Make a node of the sort we want. */ - t = make_node (METHOD_TYPE); - if (TREE_CODE (type) != FUNCTION_TYPE) abort (); - TYPE_METHOD_BASETYPE (t) = TYPE_MAIN_VARIANT (basetype); - TREE_TYPE (t) = TREE_TYPE (type); - - /* The actual arglist for this function includes a "hidden" argument - which is "this". Put it into the list of argument types. */ - - TYPE_ARG_TYPES (t) - = tree_cons (NULL_TREE, - build_pointer_type (basetype), TYPE_ARG_TYPES (type)); - - /* If we already have such a type, use the old one and free this one. */ - hashcode = TYPE_HASH (basetype) + TYPE_HASH (type); - t = type_hash_canon (hashcode, t); - - if (!COMPLETE_TYPE_P (t)) - layout_type (t); - - return t; + return build_method_type_directly (basetype, + TREE_TYPE (type), + TYPE_ARG_TYPES (type)); } /* Construct, lay out and return the type of offsets to a value