note
	description: "Representation of an Eiffel type."
	library: "Free implementation of ELKS library"
	status: "See notice at end of class."
	legal: "See notice at end of class."
	date: "$Date: 2020-05-19 14:32:38 +0000 (Tue, 19 May 2020) $"
	revision: "$Revision: 104260 $"

frozen class 
	TYPE [G]

create {NONE}
convert
	to_string_8: {STRING_8,
		READABLE_STRING_8},
	to_string_32: {STRING_32,
		READABLE_STRING_32,
		STRING_GENERAL,
		READABLE_STRING_GENERAL}

feature {NONE} -- Initialization

	default_create
			-- Process instances of classes with no creation clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end
	
feature -- Access

	generating_type: TYPE [detachable TYPE [G]]
			-- Type of current object
			-- (type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generating_type_not_void: Result /= Void
		end

	generator: STRING_8
			-- Name of current object's generating class
			-- (base class of the type of which it is a direct instance)
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			generator_not_void: Result /= Void
			generator_not_empty: not Result.is_empty
		end

	generic_parameter_type (i: INTEGER_32): TYPE [detachable ANY]
			-- i-th generic parameter of Eiffel type represented by Current
		require
			i_large_enough: i >= 1
			i_small_enough: i <= generic_parameter_count
		external
			"built_in"
		ensure
			generic_parameter_not_void: Result /= Void
		end

	hash_code: INTEGER_32
			-- Hash code value
		do
			Result := type_id
		ensure -- from HASHABLE
			good_hash_value: Result >= 0
		end

	name: IMMUTABLE_STRING_8
			-- Name of Eiffel type represented by Current, using Eiffel style guidelines
			-- as specified in OOSC2 (e.g. COMPARABLE, HASH_TABLE [FOO, BAR], ...)
			-- Consider using name_32 instead.
		local
			s: like runtime_name
		do
			Result := internal_name
			if not attached Result then
				s := runtime_name
				create Result.make_from_string (if attached {READABLE_STRING_8} s as s8 then
						s8
					else
						{UTF_CONVERTER}.utf_32_string_to_utf_8_string_8 (s)
					end)
				internal_name := Result
			end
		ensure
			name_not_void: Result /= Void
		end

	name_32: IMMUTABLE_STRING_32
			-- Name of Eiffel type represented by Current, using Eiffel style guidelines
			-- as specified in OOSC2 (e.g. COMPARABLE, HASH_TABLE [FOO, BAR], ...)
		do
			Result := internal_name_32
			if not attached Result then
				create Result.make_from_string_general (runtime_name)
				internal_name_32 := Result
			end
		ensure
			name_32_attached: attached Result
		end

	type_id: INTEGER_32
			-- Id of the Eiffel type represented by Current
		external
			"built_in"
		ensure
			type_id_not_negative: Result >= 0
		end
	
feature -- Measurement

	generic_parameter_count: INTEGER_32
			-- Number of generic parameters in Eiffel type represented by Current
		external
			"built_in"
		ensure
			generic_parameter_count_not_negative: Result >= 0
		end
	
feature -- Comparison

	frozen deep_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void
			-- or attached to isomorphic object structures?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_deep_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			shallow_implies_deep: standard_equal (a, b) implies Result
			both_or_none_void: (a = Void) implies (Result = (b = Void))
			same_type: (Result and (a /= Void)) implies (b /= Void and then a.same_type (b))
			symmetric: Result implies deep_equal (b, a)
		end

	frozen equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached
			-- to objects considered equal?
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.is_equal (b))
		end

	is_conforming_to alias "<=" (other: like Current): BOOLEAN
			-- Does type represented by Current conform to type represented by other?
		require -- from PART_COMPARABLE
			other_exists: other /= Void
		do
			Result := {ISE_RUNTIME}.type_conforms_to (type_id, other.type_id)
		end

	frozen is_deep_equal alias "≡≡≡" (other: TYPE [G]): BOOLEAN
			-- Are Current and other attached to isomorphic object structures?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			shallow_implies_deep: standard_is_equal (other) implies Result
			same_type: Result implies same_type (other)
			symmetric: Result implies other.is_deep_equal (Current)
		end

	is_equal (other: like Current): BOOLEAN
			-- Is other attached to an object considered
			-- equal to current object?
		require -- from ANY
			other_not_void: other /= Void
		do
			Result := type_id = other.type_id
		ensure -- from ANY
			symmetric: Result implies other ~ Current
			consistent: standard_is_equal (other) implies Result
		end

	is_greater alias ">" (other: TYPE [G]): BOOLEAN
			-- Is current object greater than other?
			-- (from PART_COMPARABLE)
		require -- from PART_COMPARABLE
			other_exists: other /= Void
		do
			Result := other < Current
		end

	is_greater_equal alias ">=" alias "" (other: TYPE [G]): BOOLEAN
			-- Is current object greater than or equal to other?
			-- (from PART_COMPARABLE)
		require -- from PART_COMPARABLE
			other_exists: other /= Void
		do
			Result := (other < Current) or (Current ~ other)
		end

	is_strictly_conforming_to alias "<" (other: like Current): BOOLEAN
			-- Does type represented by Current conform to type represented by other and differ from it?
		require -- from PART_COMPARABLE
			other_exists: other /= Void
		do
			Result := type_id /= other.type_id and then is_conforming_to (other)
		end

	frozen standard_equal (a: detachable ANY; b: like arg #1): BOOLEAN
			-- Are a and b either both void or attached to
			-- field-by-field identical objects of the same type?
			-- Always uses default object comparison criterion.
			-- (from ANY)
		do
			if a = Void then
				Result := b = Void
			else
				Result := b /= Void and then a.standard_is_equal (b)
			end
		ensure -- from ANY
			instance_free: class
			definition: Result = (a = Void and b = Void) or else ((a /= Void and b /= Void) and then a.standard_is_equal (b))
		end

	frozen standard_is_equal alias "" (other: TYPE [G]): BOOLEAN
			-- Is other attached to an object of the same type
			-- as current object, and field-by-field identical to it?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			same_type: Result implies same_type (other)
			symmetric: Result implies other.standard_is_equal (Current)
		end
	
feature -- Status report

	conforms_to (other: ANY): BOOLEAN
			-- Does type of current object conform to type
			-- of other (as per Eiffel: The Language, chapter 13)?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		end

	has_default: BOOLEAN
			-- Is current type a type that has a default value?
			-- I.e. a detachable type or an expanded type.
		external
			"built_in"
		end

	is_attached: BOOLEAN
			-- Is current type attached?
		external
			"built_in"
		end

	is_deferred: BOOLEAN
			-- Is current type a deferred type?
		external
			"built_in"
		end

	is_expanded: BOOLEAN
			-- Is current type an expanded type?
		external
			"built_in"
		end

	is_hashable: BOOLEAN
			-- May current object be hashed?
			-- (True by default.)
			-- (from HASHABLE)
		do
			Result := True
		end

	same_type (other: ANY): BOOLEAN
			-- Is type of current object identical to type of other?
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		external
			"built_in"
		ensure -- from ANY
			definition: Result = (conforms_to (other) and other.conforms_to (Current))
		end
	
feature -- Conversion

	adapt alias "[]" (g: detachable G): detachable G
			-- Adapts g or calls necessary conversion routine to adapt g
		do
			Result := g
		ensure
			adapted: Result ~ g
		end

	attempt alias "#?" (obj: detachable separate ANY): detachable G
		obsolete "Use `attempted' or its operator alias `/'. [2017-05-31]"
			-- Result of assignment attempt of obj to entity of type G
		do
			Result := attempted (obj)
		ensure
			assigned_or_void: Result = obj or Result = default_detachable_value
		end

	attempted alias "/" (obj: detachable separate ANY): detachable G
			-- If possible, obj understood as an object of type G;
			-- If not, default detachable value of type G..
		do
			if attached {G} obj as l_g then
				Result := l_g
			end
		ensure
			assigned_or_void: Result = obj or Result = default_detachable_value
		end

	default: G
		require
			has_default: has_default
		local
			r: detachable G
		do
			check
					attached r
			then
				Result := r
			end
		end

	default_detachable_value: detachable G
		do
		end
	
feature -- Duplication

	frozen clone (other: detachable ANY): like other
		obsolete "Use `twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- equal to other
			--
			-- For non-void other, clone calls copy;
			-- to change copying/cloning semantics, redefine copy.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.twin
			end
		ensure -- from ANY
			instance_free: class
			equal: Result ~ other
		end

	copy (other: TYPE [G])
			-- Update current object using fields of object attached
			-- to other, so as to yield equal objects.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_equal: Current ~ other
		end

	frozen deep_clone (other: detachable ANY): like other
		obsolete "Use `deep_twin' instead. [2017-05-31]"
			-- Void if other is void: otherwise, new object structure
			-- recursively duplicated from the one attached to other
			-- (from ANY)
		do
			if other /= Void then
				Result := other.deep_twin
			end
		ensure -- from ANY
			instance_free: class
			deep_equal: deep_equal (other, Result)
		end

	frozen deep_copy (other: TYPE [G])
			-- Effect equivalent to that of:
			--		copy (other . deep_twin)
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
		do
			copy (other.deep_twin)
		ensure -- from ANY
			deep_equal: deep_equal (Current, other)
		end

	frozen deep_twin: TYPE [G]
			-- New object structure recursively duplicated from Current.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			deep_twin_not_void: Result /= Void
			deep_equal: deep_equal (Current, Result)
		end

	frozen standard_clone (other: detachable ANY): like other
		obsolete "Use `standard_twin' instead. [2017-05-31]"
			-- Void if other is void; otherwise new object
			-- field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		do
			if other /= Void then
				Result := other.standard_twin
			end
		ensure -- from ANY
			instance_free: class
			equal: standard_equal (Result, other)
		end

	frozen standard_copy (other: TYPE [G])
			-- Copy every field of other onto corresponding field
			-- of current object.
			-- (from ANY)
		require -- from ANY
			other_not_void: other /= Void
			type_identity: same_type (other)
		external
			"built_in"
		ensure -- from ANY
			is_standard_equal: standard_is_equal (other)
		end

	frozen standard_twin: TYPE [G]
			-- New object field-by-field identical to other.
			-- Always uses default copying semantics.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			standard_twin_not_void: Result /= Void
			equal: standard_equal (Result, Current)
		end

	frozen twin: TYPE [G]
			-- New object equal to Current
			-- twin calls copy; to change copying/twinning semantics, redefine copy.
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			twin_not_void: Result /= Void
			is_equal: Result ~ Current
		end
	
feature -- Basic operations

	frozen as_attached: attached TYPE [G]
		obsolete "Remove calls to this feature. [2017-05-31]"
			-- Attached version of Current.
			-- (Can be used during transitional period to convert
			-- non-void-safe classes to void-safe ones.)
			-- (from ANY)
		do
			Result := Current
		end

	frozen any_default: detachable TYPE [G]
			-- Default value of object's type
			-- (from ANY)
		do
		end

	frozen default_pointer: POINTER
			-- Default value of type POINTER
			-- (Avoid the need to write p.default for
			-- some p of type POINTER.)
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end

	default_rescue
			-- Process exception for routines with no Rescue clause.
			-- (Default: do nothing.)
			-- (from ANY)
		do
		end

	frozen do_nothing
			-- Execute a null action.
			-- (from ANY)
		do
		ensure -- from ANY
			instance_free: class
		end
	
feature {NONE} -- Implementation

	runtime_name: STRING_8
			-- Name of Eiffel type represented by Current, using Eiffel style guidelines
			-- as specified in OOSC2 (e.g. COMPARABLE, HASH_TABLE [FOO, BAR], ...)
		external
			"built_in"
		ensure
			name_not_void: Result /= Void
		end
	
feature -- Features from STRING needed here for the transition period (see convert clause)

	as_lower: STRING_8
		obsolete "Use 'name_32.as_lower' instead. [2017-05-31]"
			-- New object with all letters of the name of the Eiffel type
			-- represented by Current in lower case.
			-- This feature from STRING is needed here for the
			-- transition period (see convert clause).
		do
			create Result.make_from_string (name);
			Result.to_lower
		ensure
			as_lower_not_void: Result /= Void
			definition: Result.same_string (name.as_lower)
		end

	as_upper: STRING_8
		obsolete "Use 'name_32.as_upper' instead. [2017-05-31]"
			-- New object with all letters of the name of the Eiffel type
			-- represented by Current in upper case.
			-- This feature from STRING is needed here for the
			-- transition period (see convert clause).
		do
			create Result.make_from_string (name);
			Result.to_upper
		ensure
			as_upper_not_void: Result /= Void
			definition: Result.same_string (name.as_upper)
		end

	is_case_insensitive_equal (other: STRING_8): BOOLEAN
		obsolete "Use 'name_32.is_case_insensitive_equal (other)' instead. [2017-05-31]"
			-- Is the name of the Eiffel type represented by Current
			-- made of same character sequence as other regardless
			-- of casing (possibly with a different capacity)?
			-- This feature from STRING is needed here for the
			-- transition period (see convert clause).
		require
			other_not_void: other /= Void
		do
			Result := name.is_case_insensitive_equal (other)
		ensure
			definition: Result = name.is_case_insensitive_equal (other)
		end

	plus alias "+" (other: STRING_8): STRING_8
		obsolete "Use 'name_32 + other' instead. [2017-05-31]"
			-- Append a copy of 's' at the end of a copy of the name of the
			-- Eiffel type represented by Current, then return the Result.
			-- This feature from STRING is needed here for the
			-- transition period (see convert clause).
		require
			argument_not_void: other /= Void
		do
			create Result.make (name.count + other.count);
			Result.append (name);
			Result.append (other)
		ensure
			result_exists: Result /= Void
			definition: Result.same_string (name + other)
		end

	same_string (other: STRING_8): BOOLEAN
		obsolete "Use 'name_32.same_string (other)' instead. [2017-05-31]"
			-- Do the name of the Eiffel type represented by Current
			-- and other have same character sequence?
			-- This feature from STRING is needed here for the
			-- transition period (see convert clause).
		require
			other_not_void: other /= Void
		do
			Result := name.same_string (other)
		ensure
			definition: Result = name.same_string (other)
		end

	to_string_32: STRING_32
		obsolete "Use 'name_32' instead. [2017-05-31]"
			-- Name of type
		do
			create Result.make_from_string (name_32)
		ensure
			to_string_32_not_void: Result /= Void
		end

	to_string_8: STRING_8
		obsolete "Use `name_32' instead. [2017-05-31]"
		do
			create Result.make_from_string (name)
		ensure
			to_string_8_not_void: Result /= Void
		end
	
feature {NONE} -- Implementation: Access

	internal_name: detachable IMMUTABLE_STRING_8
			-- Storage for once per object name.
		note
			option: stable, transient
		attribute
		end

	internal_name_32: detachable IMMUTABLE_STRING_32
			-- Storage for once per object name_32.
		note
			option: stable, transient
		attribute
		end
	
feature -- Output

	debug_output: READABLE_STRING_32
			-- String that should be displayed in debugger to represent Current.
		do
			Result := name_32
		ensure -- from DEBUG_OUTPUT
			result_not_void: Result /= Void
		end

	Io: STD_FILES
			-- Handle to standard file setup
			-- (from ANY)
		once
			create Result;
			Result.set_output_default
		ensure -- from ANY
			instance_free: class
			io_not_void: Result /= Void
		end

	out: STRING_8
			-- New string containing terse printable representation
			-- of current object
		do
			if attached {READABLE_STRING_8} name_32 as n then
				create Result.make_from_string (n)
			elseif attached {READABLE_STRING_8} name as n then
				create Result.make_from_string (n)
			else
				check
					known_string_type: False
				then
				end
			end
		ensure -- from ANY
			out_not_void: Result /= Void
		end

	print (o: detachable ANY)
			-- Write terse external representation of o
			-- on standard output.
			-- (from ANY)
		local
			s: READABLE_STRING_8
		do
			if attached o then
				s := o.out
				if attached {READABLE_STRING_32} s as s32 then
					Io.put_string_32 (s32)
				elseif attached {READABLE_STRING_8} s as s8 then
					Io.put_string (s8)
				else
					Io.put_string_32 (s.as_string_32)
				end
			end
		ensure -- from ANY
			instance_free: class
		end

	frozen tagged_out: STRING_8
			-- New string containing terse printable representation
			-- of current object
			-- (from ANY)
		external
			"built_in"
		ensure -- from ANY
			tagged_out_not_void: Result /= Void
		end
	
feature -- Platform

	Operating_environment: OPERATING_ENVIRONMENT
			-- Objects available from the operating system
			-- (from ANY)
		once
			create Result
		ensure -- from ANY
			instance_free: class
			operating_environment_not_void: Result /= Void
		end
	
feature {NONE} -- Retrieval

	frozen internal_correct_mismatch
			-- Called from runtime to perform a proper dynamic dispatch on correct_mismatch
			-- from MISMATCH_CORRECTOR.
			-- (from ANY)
		local
			l_msg: STRING_32
			l_exc: EXCEPTIONS
		do
			if attached {MISMATCH_CORRECTOR} Current as l_corrector then
				l_corrector.correct_mismatch
			else
				create l_msg.make_from_string ("Mismatch: ".as_string_32)
				create l_exc;
				l_msg.append (generating_type.name_32);
				l_exc.raise_retrieval_exception (l_msg)
			end
		end
	
invariant
		-- from ANY
	reflexive_equality: standard_is_equal (Current)
	reflexive_conformance: conforms_to (Current)

note
	copyright: "Copyright (c) 1984-2020, Eiffel Software and others"
	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
	source: "[
		Eiffel Software
		5949 Hollister Ave., Goleta, CA 93117 USA
		Telephone 805-685-1006, Fax 805-685-6869
		Website http://www.eiffel.com
		Customer support http://support.eiffel.com
	]"

end -- class TYPE

Generated by ISE EiffelStudio