Class: RCGTK::ConstantInteger Abstract

Inherits:
ConstantNumber show all
Includes:
Filigree::AbstractClass
Defined in:
lib/rcgtk/value.rb

Overview

This class is abstract.

All integer constants inherit from this class.

Direct Known Subclasses

Int1, Int16, Int32, Int64, Int8

Instance Attribute Summary collapse

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from ConstantNumber

type, #type

Methods inherited from Constant

#addr_space_cast, #bitcast_to, #get_element_ptr, #get_element_ptr_in_bounds

Methods inherited from User

#operands

Methods inherited from Value

#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast

Methods included from BindingClass

#==

Constructor Details

#initialize(overloaded0 = nil, overloaded1 = nil, size = nil) ⇒ ConstantInteger

The constructor for ConstantInteger’s various sub-classes. This constructor is a bit complicated due to having two overloaded parameters, but once you see the valid combinations it is a bit simpler.

Examples:

Constant (signed) integer from Ruby Integer:

Int32.new(128)

Constant (signed) base 8 integer from Ruby String:

Int32.new('72', 8)

Constant integer of all 1s:

Int32.new

Parameters:

  • overloaded0 (FFI::Pointer, Integer, String, nil) (defaults to: nil)

    Pointer to a ConstantInteger, value, or string representing value.

  • overloaded1 (Boolean, Integer) (defaults to: nil)

    Signed or unsigned (when overloaded0 is Integer) or base used to decode string value.

  • size (Integer) (defaults to: nil)

    Optional length of string to use.



575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/rcgtk/value.rb', line 575

def initialize(overloaded0 = nil, overloaded1 = nil, size = nil)
	@ptr =
	case overloaded0
	when FFI::Pointer
		overloaded0

	when Integer
		@signed = overloaded1 or true

		Bindings.const_int(self.type, overloaded0, @signed.to_i)

	when String
		base = overloaded1 or 10

		if size
			Bindings.const_int_of_string_and_size(self.type, overloaded0, size, base)
		else
			Bindings.const_int_of_string(self.type, overloaded0, base)
		end
	else
		@signed = true

		Bindings.const_all_ones(self.type)
	end
end

Instance Attribute Details

#signedBoolean (readonly)

Returns If the integer is signed or not.

Returns:

  • (Boolean)

    If the integer is signed or not.



555
556
557
# File 'lib/rcgtk/value.rb', line 555

def signed
  @signed
end

Instance Method Details

#%(rhs) ⇒ ConstantInteger

Modulo this value by another value. Uses signed modulo.

Parameters:

Returns:



734
735
736
# File 'lib/rcgtk/value.rb', line 734

def %(rhs)
	self.class.new(Bindings.const_s_rem(@ptr, rhs))
end

#*(rhs) ⇒ ConstantInteger

Multiply this value with another value.

Parameters:

Returns:



674
675
676
# File 'lib/rcgtk/value.rb', line 674

def *(rhs)
	self.class.new(Bindings.const_mul(@ptr, rhs))
end

#+(rhs) ⇒ ConstantInteger

Add this value with another value.

Parameters:

Returns:



612
613
614
# File 'lib/rcgtk/value.rb', line 612

def +(rhs)
	self.class.new(Bindings.const_add(@ptr, rhs))
end

#-(rhs) ⇒ ConstantInteger

Subtract a value from this value.

Parameters:

Returns:



643
644
645
# File 'lib/rcgtk/value.rb', line 643

def -(rhs)
	self.class.new(Bindings.const_sub(@ptr, rhs))
end

#-@ConstantInteger

Negate this value.

Returns:



752
753
754
# File 'lib/rcgtk/value.rb', line 752

def -@
	self.class.new(Bindings.const_neg(@ptr))
end

#/(rhs) ⇒ ConstantInteger

Divide this value by another value. Uses signed division.

Parameters:

Returns:



705
706
707
# File 'lib/rcgtk/value.rb', line 705

def /(rhs)
	self.class.new(Bindings.const_s_div(@ptr, rhs))
end

#and(rhs) ⇒ ConstantInteger

Bitwise AND this value with another.

Parameters:

Returns:



837
838
839
# File 'lib/rcgtk/value.rb', line 837

def and(rhs)
	self.class.new(Bindings.const_and(@ptr, rhs))
end

#ashr(bits) ⇒ ConstantInteger Also known as: >>

Arithmetic right shift.

Parameters:

  • bits (Integer)

    Number of bits to shift.

Returns:



818
819
820
# File 'lib/rcgtk/value.rb', line 818

def ashr(bits)
	self.class.new(Bindings.const_a_shr(@ptr, bits))
end

#cast(type, signed = true) ⇒ ConstantNumber

Cast this constant integer to another number type.

Parameters:

  • type (NumberType)

    Desired type to cast to.

  • signed (Boolean) (defaults to: true)

    Is the value signed or not.

Returns:



876
877
878
# File 'lib/rcgtk/value.rb', line 876

def cast(type, signed = true)
	type.value_class.new(Bindings.const_int_cast(@ptr, check_cg_type(type, NumberType), signed.to_i))
end

#cmp(pred, rhs) ⇒ Int1

Compare this value to another value.

Parameters:

  • pred (Symbol)

    An integer predicate.

  • rhs (ConstantInteger)

    Value to compare to.

Returns:

  • (Int1)

    Value used to represent a Boolean value.

See Also:



888
889
890
# File 'lib/rcgtk/value.rb', line 888

def cmp(pred, rhs)
	Int1.new(Bindings.const_i_cmp(pred, @ptr, rhs))
end

#extact_sdiv(rhs) ⇒ ConstantInteger

Divide this value by another value. Uses exact signed division.

Parameters:

Returns:



714
715
716
# File 'lib/rcgtk/value.rb', line 714

def extact_sdiv(rhs)
	self.class.new(Bindings.const_extact_s_div(@ptr, rhs))
end

#lshr(bits) ⇒ ConstantInteger

Logical right shift.

Parameters:

  • bits (Integer)

    Number of bits to shift.

Returns:



828
829
830
# File 'lib/rcgtk/value.rb', line 828

def lshr(bits)
	self.class.new(Bindings.const_l_shr(@ptr, bits))
end

#notConstantInteger

Bitwise NOT this value.

Returns:



862
863
864
# File 'lib/rcgtk/value.rb', line 862

def not
	self.class.new(Bindings.const_not(@ptr))
end

#nsw_add(rhs) ⇒ ConstantInteger

Add this value with another value. Performs no signed wrap addition.

Parameters:

Returns:



622
623
624
# File 'lib/rcgtk/value.rb', line 622

def nsw_add(rhs)
	self.class.new(Bindings.const_nsw_add(@ptr, rhs))
end

#nsw_mul(rhs) ⇒ ConstantInteger

Multiply this value with another value. Perform no signed wrap multiplication.

Parameters:

Returns:



684
685
686
# File 'lib/rcgtk/value.rb', line 684

def nsw_mul(rhs)
	self.class.new(Bindings.const_nsw_mul(@ptr, rhs))
end

#nsw_negConstantInteger

Negate this value. Uses no signed wrap negation.

Returns:



759
760
761
# File 'lib/rcgtk/value.rb', line 759

def nsw_neg
	self.class.new(Bindings.const_nsw_neg(@ptr))
end

#nsw_sub(rhs) ⇒ ConstantInteger

Subtract a value from this value. Performs no signed wrap subtraction.

Parameters:

Returns:



653
654
655
# File 'lib/rcgtk/value.rb', line 653

def nsw_sub(rhs)
	self.class.new(Bindings.const_nsw_sub(@ptr, rhs))
end

#nuw_add(rhs) ⇒ ConstantInteger

Add this value with another value. Performs no unsigned wrap addition.

Parameters:

Returns:



632
633
634
# File 'lib/rcgtk/value.rb', line 632

def nuw_add(rhs)
	self.class.new(Bindings.const_nuw_add(@ptr, rhs))
end

#nuw_mul(rhs) ⇒ ConstantInteger

Multiply this value with another value. Perform no unsigned wrap multiplication.

Parameters:

Returns:



694
695
696
# File 'lib/rcgtk/value.rb', line 694

def nuw_mul(rhs)
	self.class.new(Bindings.const_nuw_mul(@ptr, rhs))
end

#nuw_negConstantInteger

Negate this value. Uses no unsigned wrap negation.

Returns:



766
767
768
# File 'lib/rcgtk/value.rb', line 766

def nuw_neg
	self.class.new(Bindings.const_nuw_neg(@ptr))
end

#nuw_sub(rhs) ⇒ ConstantInteger

Subtract a value from this value. Performs no unsigned wrap subtraction.

Parameters:

Returns:



663
664
665
# File 'lib/rcgtk/value.rb', line 663

def nuw_sub(rhs)
	self.class.new(Bindings.const_nuw_sub(@ptr, rhs))
end

#or(rhs) ⇒ ConstantInteger

Bitwise OR this value with another.

Parameters:

Returns:



846
847
848
# File 'lib/rcgtk/value.rb', line 846

def or(rhs)
	self.class.new(Bindings.const_or(@ptr, rhs))
end

#shift(dir, bits, mode = :arithmetic) ⇒ ConstantInteger

A wrapper method around the #shift_left and #shift_right methods.

Parameters:

  • dir (:left, :right)

    The direction to shift.

  • bits (Integer)

    Number of bits to shift.

  • mode (:arithmetic, :logical) (defaults to: :arithmetic)

    Shift mode for right shifts.

Returns:



782
783
784
785
786
787
# File 'lib/rcgtk/value.rb', line 782

def shift(dir, bits, mode = :arithmetic)
	case dir
	when :left	then shift_left(bits)
	when :right	then shift_right(bits, mode)
	end
end

#shift_left(bits) ⇒ ConstantInteger Also known as: shl, <<

Shift the value left a specific number of bits.

Parameters:

  • bits (Integer)

    Number of bits to shift.

Returns:



794
795
796
# File 'lib/rcgtk/value.rb', line 794

def shift_left(bits)
	self.class.new(Bindings.const_shl(@ptr, bits))
end

#shift_right(bits, mode = :arithmetic) ⇒ ConstantInteger

Shift the value right a specific number of bits.

Parameters:

  • bits (Integer)

    Number of bits to shift.

  • mode (:arithmetic, :logical) (defaults to: :arithmetic)

    Shift mode.

Returns:



806
807
808
809
810
811
# File 'lib/rcgtk/value.rb', line 806

def shift_right(bits, mode = :arithmetic)
	case mode
	when :arithmetic	then ashr(bits)
	when :logical		then lshr(bits)
	end
end

#to_f(type) ⇒ ConstantReal

Convert this integer to a float.

Parameters:

  • type (RealType)

    Type of float to convert to.

Returns:

  • (ConstantReal)

    This value as a floating point value of the given type.



897
898
899
# File 'lib/rcgtk/value.rb', line 897

def to_f(type)
	type.value_class.new(Bindings.send(@signed ? :const_si_to_fp : :const_ui_to_fp, @ptr, check_cg_type(type, FloatingPointType)))
end

#udiv(rhs) ⇒ ConstantInteger

Divide this value by another value. Uses unsigned division.

Parameters:

Returns:



723
724
725
# File 'lib/rcgtk/value.rb', line 723

def udiv(rhs)
	self.class.new(Bindings.const_u_div(@ptr, rhs))
end

#urem(rhs) ⇒ ConstantInteger

Modulo this value by another value. Uses unsigned modulo.

Parameters:

Returns:



743
744
745
# File 'lib/rcgtk/value.rb', line 743

def urem(rhs)
	self.class.new(Bindings.const_u_rem(@ptr, rhs))
end

#value(extension = :sign) ⇒ Integer

Get the value of this constant as a signed or unsigned long long.

Parameters:

  • extension (:sign, :zero) (defaults to: :sign)

    Extension method.

Returns:

  • (Integer)


906
907
908
909
910
911
# File 'lib/rcgtk/value.rb', line 906

def value(extension = :sign)
	case extension
	when :sign then Bindings.const_int_get_s_ext_value(@ptr)
	when :zero then Bindings.const_int_get_z_ext_value(@ptr)
	end
end

#xor(rhs) ⇒ ConstantInteger

Bitwise XOR this value with another.

Parameters:

Returns:



855
856
857
# File 'lib/rcgtk/value.rb', line 855

def xor(rhs)
	self.class.new(Bindings.const_xor(@ptr, rhs))
end