FreeBSD/contrib/gcc/cp/typeck.c
/* Return true if T1 and T2 are related as allowed by STRICT.  STRICT
   is a bitwise-or of the COMPARE_* flags.  */
Return true if T1 and T2 are related as allowed by STRICT.  STRICT
is a bitwise-or of the COMPARE_* flags.
Return true if T1 and T2 are related as allowed by STRICT . STRICT is a bitwise - or of the COMPARE_ * flags .
bool
comptypes (tree t1, tree t2, int strict)
{
  if (t1 == t2)
    return true;
  if (t1 == error_mark_node || t2 == error_mark_node)
    return false;
  gcc_assert (TYPE_P (t1) && TYPE_P (t2));
  if (TREE_CODE (t1) == TYPENAME_TYPE)
    {
      tree resolved = resolve_typename_type (t1, true);
      if (resolved != error_mark_node)
	t1 = resolved;
    }
  if (TREE_CODE (t2) == TYPENAME_TYPE)
    {
      tree resolved = resolve_typename_type (t2, true);
      if (resolved != error_mark_node)
	t2 = resolved;
    }
  if (TREE_CODE (t1) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t1)
      && TYPE_ORIG_SIZE_TYPE (t1))
    t1 = TYPE_ORIG_SIZE_TYPE (t1);
  if (TREE_CODE (t2) == INTEGER_TYPE && TYPE_IS_SIZETYPE (t2)
      && TYPE_ORIG_SIZE_TYPE (t2))
    t2 = TYPE_ORIG_SIZE_TYPE (t2);
  if (TYPE_PTRMEMFUNC_P (t1))
    t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);
  if (TYPE_PTRMEMFUNC_P (t2))
    t2 = TYPE_PTRMEMFUNC_FN_TYPE (t2);
  if (TREE_CODE (t1) != TREE_CODE (t2))
    return false;
  if (TREE_CODE (t1) != ARRAY_TYPE
      && TYPE_QUALS (t1) != TYPE_QUALS (t2))
    return false;
  if (TYPE_FOR_JAVA (t1) != TYPE_FOR_JAVA (t2))
    return false;
  if (TREE_CODE (t1) != ARRAY_TYPE
      && TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
    return true;
  switch (TREE_CODE (t1))
    {
    case TEMPLATE_TEMPLATE_PARM:
    case BOUND_TEMPLATE_TEMPLATE_PARM:
      if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
	  || TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
	return false;
      if (!comp_template_parms
	  (DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t1)),
	   DECL_TEMPLATE_PARMS (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t2))))
	return false;
      if (TREE_CODE (t1) == TEMPLATE_TEMPLATE_PARM)
	break;
      strict = COMPARE_STRICT;
    case RECORD_TYPE:
    case UNION_TYPE:
      if (TYPE_TEMPLATE_INFO (t1) && TYPE_TEMPLATE_INFO (t2)
	  && (TYPE_TI_TEMPLATE (t1) == TYPE_TI_TEMPLATE (t2)
	      || TREE_CODE (t1) == BOUND_TEMPLATE_TEMPLATE_PARM)
	  && comp_template_args (TYPE_TI_ARGS (t1), TYPE_TI_ARGS (t2)))
	break;
      if ((strict & COMPARE_BASE) && DERIVED_FROM_P (t1, t2))
	break;
      else if ((strict & COMPARE_DERIVED) && DERIVED_FROM_P (t2, t1))
	break;
      return false;
    case OFFSET_TYPE:
      if (!comptypes (TYPE_OFFSET_BASETYPE (t1), TYPE_OFFSET_BASETYPE (t2),
		      strict & ~COMPARE_REDECLARATION))
	return false;
      if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
	return false;
      break;
      case BLOCK_POINTER_TYPE:
	 if (TREE_CODE (t2) == BLOCK_POINTER_TYPE)
	 {
	   tree pt1 = TREE_TYPE (t1);
	   tree pt2 = TREE_TYPE (t2);
	   if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (pt1),
							  TREE_TYPE (pt2)))
	     return false;
	   if (!compparms (TYPE_ARG_TYPES (pt1), TYPE_ARG_TYPES (pt2)))
	     return false;
	   break;
	 }
    case POINTER_TYPE:
    case REFERENCE_TYPE:
      if (TYPE_MODE (t1) != TYPE_MODE (t2)
	  || TYPE_REF_CAN_ALIAS_ALL (t1) != TYPE_REF_CAN_ALIAS_ALL (t2)
	  || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
	return false;
      break;
    case METHOD_TYPE:
    case FUNCTION_TYPE:
      if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
	return false;
      if (!compparms (TYPE_ARG_TYPES (t1), TYPE_ARG_TYPES (t2)))
	return false;
      break;
    case ARRAY_TYPE:
      if (!comp_array_types (t1, t2, !!(strict & COMPARE_REDECLARATION)))
	return false;
      break;
    case TEMPLATE_TYPE_PARM:
      if (TEMPLATE_TYPE_IDX (t1) != TEMPLATE_TYPE_IDX (t2)
	  || TEMPLATE_TYPE_LEVEL (t1) != TEMPLATE_TYPE_LEVEL (t2))
	return false;
      break;
    case TYPENAME_TYPE:
      if (!cp_tree_equal (TYPENAME_TYPE_FULLNAME (t1),
			  TYPENAME_TYPE_FULLNAME (t2)))
	return false;
      if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
	return false;
      break;
    case UNBOUND_CLASS_TEMPLATE:
      if (!cp_tree_equal (TYPE_IDENTIFIER (t1), TYPE_IDENTIFIER (t2)))
	return false;
      if (!same_type_p (TYPE_CONTEXT (t1), TYPE_CONTEXT (t2)))
	return false;
      break;
    case COMPLEX_TYPE:
      if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
	return false;
      break;
    case VECTOR_TYPE:
      if (TYPE_VECTOR_SUBPARTS (t1) != TYPE_VECTOR_SUBPARTS (t2)
	  || !same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)))
	return false;
      break;
    default:
      return false;
    }
  return targetm.comp_type_attributes (t1, t2);
}
bool comptypes ( tree t1 , tree t2 , int strict ) { if ( t1 == t2 ) return true ; if ( t1 == error_mark_node || t2 == error_mark_node ) return false ; gcc_assert ( TYPE_P ( t1 ) && TYPE_P ( t2 ) ) ; if ( TREE_CODE ( t1 ) == TYPENAME_TYPE ) { tree resolved = resolve_typename_type ( t1 , true ) ; if ( resolved != error_mark_node ) t1 = resolved ; } if ( TREE_CODE ( t2 ) == TYPENAME_TYPE ) { tree resolved = resolve_typename_type ( t2 , true ) ; if ( resolved != error_mark_node ) t2 = resolved ; } if ( TREE_CODE ( t1 ) == INTEGER_TYPE && TYPE_IS_SIZETYPE ( t1 ) && TYPE_ORIG_SIZE_TYPE ( t1 ) ) t1 = TYPE_ORIG_SIZE_TYPE ( t1 ) ; if ( TREE_CODE ( t2 ) == INTEGER_TYPE && TYPE_IS_SIZETYPE ( t2 ) && TYPE_ORIG_SIZE_TYPE ( t2 ) ) t2 = TYPE_ORIG_SIZE_TYPE ( t2 ) ; if ( TYPE_PTRMEMFUNC_P ( t1 ) ) t1 = TYPE_PTRMEMFUNC_FN_TYPE ( t1 ) ; if ( TYPE_PTRMEMFUNC_P ( t2 ) ) t2 = TYPE_PTRMEMFUNC_FN_TYPE ( t2 ) ; if ( TREE_CODE ( t1 ) != TREE_CODE ( t2 ) ) return false ; if ( TREE_CODE ( t1 ) != ARRAY_TYPE && TYPE_QUALS ( t1 ) != TYPE_QUALS ( t2 ) ) return false ; if ( TYPE_FOR_JAVA ( t1 ) != TYPE_FOR_JAVA ( t2 ) ) return false ; if ( TREE_CODE ( t1 ) != ARRAY_TYPE && TYPE_MAIN_VARIANT ( t1 ) == TYPE_MAIN_VARIANT ( t2 ) ) return true ; switch ( TREE_CODE ( t1 ) ) { case TEMPLATE_TEMPLATE_PARM : case BOUND_TEMPLATE_TEMPLATE_PARM : if ( TEMPLATE_TYPE_IDX ( t1 ) != TEMPLATE_TYPE_IDX ( t2 ) || TEMPLATE_TYPE_LEVEL ( t1 ) != TEMPLATE_TYPE_LEVEL ( t2 ) ) return false ; if ( ! comp_template_parms ( DECL_TEMPLATE_PARMS ( TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL ( t1 ) ) , DECL_TEMPLATE_PARMS ( TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL ( t2 ) ) ) ) return false ; if ( TREE_CODE ( t1 ) == TEMPLATE_TEMPLATE_PARM ) break ; strict = COMPARE_STRICT ; case RECORD_TYPE : case UNION_TYPE : if ( TYPE_TEMPLATE_INFO ( t1 ) && TYPE_TEMPLATE_INFO ( t2 ) && ( TYPE_TI_TEMPLATE ( t1 ) == TYPE_TI_TEMPLATE ( t2 ) || TREE_CODE ( t1 ) == BOUND_TEMPLATE_TEMPLATE_PARM ) && comp_template_args ( TYPE_TI_ARGS ( t1 ) , TYPE_TI_ARGS ( t2 ) ) ) break ; if ( ( strict & COMPARE_BASE ) && DERIVED_FROM_P ( t1 , t2 ) ) break ; else if ( ( strict & COMPARE_DERIVED ) && DERIVED_FROM_P ( t2 , t1 ) ) break ; return false ; case OFFSET_TYPE : if ( ! comptypes ( TYPE_OFFSET_BASETYPE ( t1 ) , TYPE_OFFSET_BASETYPE ( t2 ) , strict & ~ COMPARE_REDECLARATION ) ) return false ; if ( ! same_type_p ( TREE_TYPE ( t1 ) , TREE_TYPE ( t2 ) ) ) return false ; break ; case BLOCK_POINTER_TYPE : if ( TREE_CODE ( t2 ) == BLOCK_POINTER_TYPE ) { tree pt1 = TREE_TYPE ( t1 ) ; tree pt2 = TREE_TYPE ( t2 ) ; if ( ! same_type_ignoring_top_level_qualifiers_p ( TREE_TYPE ( pt1 ) , TREE_TYPE ( pt2 ) ) ) return false ; if ( ! compparms ( TYPE_ARG_TYPES ( pt1 ) , TYPE_ARG_TYPES ( pt2 ) ) ) return false ; break ; } case POINTER_TYPE : case REFERENCE_TYPE : if ( TYPE_MODE ( t1 ) != TYPE_MODE ( t2 ) || TYPE_REF_CAN_ALIAS_ALL ( t1 ) != TYPE_REF_CAN_ALIAS_ALL ( t2 ) || ! same_type_p ( TREE_TYPE ( t1 ) , TREE_TYPE ( t2 ) ) ) return false ; break ; case METHOD_TYPE : case FUNCTION_TYPE : if ( ! same_type_p ( TREE_TYPE ( t1 ) , TREE_TYPE ( t2 ) ) ) return false ; if ( ! compparms ( TYPE_ARG_TYPES ( t1 ) , TYPE_ARG_TYPES ( t2 ) ) ) return false ; break ; case ARRAY_TYPE : if ( ! comp_array_types ( t1 , t2 , ! ! ( strict & COMPARE_REDECLARATION ) ) ) return false ; break ; case TEMPLATE_TYPE_PARM : if ( TEMPLATE_TYPE_IDX ( t1 ) != TEMPLATE_TYPE_IDX ( t2 ) || TEMPLATE_TYPE_LEVEL ( t1 ) != TEMPLATE_TYPE_LEVEL ( t2 ) ) return false ; break ; case TYPENAME_TYPE : if ( ! cp_tree_equal ( TYPENAME_TYPE_FULLNAME ( t1 ) , TYPENAME_TYPE_FULLNAME ( t2 ) ) ) return false ; if ( ! same_type_p ( TYPE_CONTEXT ( t1 ) , TYPE_CONTEXT ( t2 ) ) ) return false ; break ; case UNBOUND_CLASS_TEMPLATE : if ( ! cp_tree_equal ( TYPE_IDENTIFIER ( t1 ) , TYPE_IDENTIFIER ( t2 ) ) ) return false ; if ( ! same_type_p ( TYPE_CONTEXT ( t1 ) , TYPE_CONTEXT ( t2 ) ) ) return false ; break ; case COMPLEX_TYPE : if ( ! same_type_p ( TREE_TYPE ( t1 ) , TREE_TYPE ( t2 ) ) ) return false ; break ; case VECTOR_TYPE : if ( TYPE_VECTOR_SUBPARTS ( t1 ) != TYPE_VECTOR_SUBPARTS ( t2 ) || ! same_type_p ( TREE_TYPE ( t1 ) , TREE_TYPE ( t2 ) ) ) return false ; break ; default : return false ; } return targetm . comp_type_attributes ( t1 , t2 ) ; }
Return true if T1 and T2 are related as allowed by STRICT.
Return true if T1 and T2 are related as allowed by STRICT .
/* Suppress errors caused by previously reported errors.  */ /* TYPENAME_TYPEs should be resolved if the qualifying scope is the
     current instantiation.  */ /*only_current_p=*/ /*only_current_p=*/ /* If either type is the internal version of sizetype, use the
     language version.  */ /* Different classes of types can't be compatible.  */ /* Qualifiers must match.  For array types, we will check when we
     recur on the array element types.  */ /* Allow for two different type nodes which have essentially the same
     definition.  Note that we already checked for equality of the type
     qualifiers (just above).  */ /* Compare the types.  Break out if they could be the same.  */ /* Don't check inheritance.  */ /* Fall through.  */ /* APPLE LOCAL begin blocks 6040305 */ /* APPLE LOCAL end blocks 6040305 */ /* Target types must match incl. qualifiers.  */ /* If we get here, we know that from a target independent POV the
     types are the same.  Make sure the target attributes are also
     the same.  */