Ruby  2.1.10p492(2016-04-01revision54464)
Macros | Functions | Variables
range.c File Reference
#include "ruby/ruby.h"
#include "ruby/encoding.h"
#include "internal.h"
#include "id.h"
#include <math.h>

Go to the source code of this file.

Macros

#define RANGE_BEG(r)   (RSTRUCT(r)->as.ary[0])
 
#define RANGE_END(r)   (RSTRUCT(r)->as.ary[1])
 
#define RANGE_EXCL(r)   (RSTRUCT(r)->as.ary[2])
 
#define RANGE_SET_BEG(r, v)   (RSTRUCT_SET(r, 0, v))
 
#define RANGE_SET_END(r, v)   (RSTRUCT_SET(r, 1, v))
 
#define RANGE_SET_EXCL(r, v)   (RSTRUCT_SET(r, 2, v))
 
#define RBOOL(v)   ((v) ? Qtrue : Qfalse)
 
#define EXCL(r)   RTEST(RANGE_EXCL(r))
 
#define BSEARCH_CHECK(val)
 
#define BSEARCH(conv)
 
#define rb_intern(str)   rb_intern_const(str)
 

Functions

static VALUE range_failed (void)
 
static VALUE range_check (VALUE *args)
 
static void range_init (VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
 
VALUE rb_range_new (VALUE beg, VALUE end, int exclude_end)
 
static void range_modify (VALUE range)
 
static VALUE range_initialize (int argc, VALUE *argv, VALUE range)
 
static VALUE range_initialize_copy (VALUE range, VALUE orig)
 
static VALUE range_exclude_end_p (VALUE range)
 
static VALUE recursive_equal (VALUE range, VALUE obj, int recur)
 
static VALUE range_eq (VALUE range, VALUE obj)
 
static int r_lt (VALUE a, VALUE b)
 
static int r_le (VALUE a, VALUE b)
 
static VALUE recursive_eql (VALUE range, VALUE obj, int recur)
 
static VALUE range_eql (VALUE range, VALUE obj)
 
static VALUE range_hash (VALUE range)
 
static void range_each_func (VALUE range, rb_block_call_func *func, VALUE arg)
 
 if (FIXNUM_P(iter[0]))
 
 if (iter[0]==INT2FIX(0))
 
static int discrete_object_p (VALUE obj)
 
static int linear_object_p (VALUE obj)
 
static VALUE range_step_size (VALUE range, VALUE args, VALUE eobj)
 
static VALUE range_step (int argc, VALUE *argv, VALUE range)
 
static int is_integer_p (VALUE v)
 
static VALUE range_bsearch (VALUE range)
 
static VALUE range_size (VALUE range)
 
static VALUE range_enum_size (VALUE range, VALUE args, VALUE eobj)
 
static VALUE range_each (VALUE range)
 
static VALUE range_begin (VALUE range)
 
static VALUE range_end (VALUE range)
 
 if (n<=0)
 
 rb_ary_push (ary[1], i)
 
static VALUE range_first (int argc, VALUE *argv, VALUE range)
 
static VALUE range_last (int argc, VALUE *argv, VALUE range)
 
static VALUE range_min (VALUE range)
 
static VALUE range_max (VALUE range)
 
int rb_range_values (VALUE range, VALUE *begp, VALUE *endp, int *exclp)
 
VALUE rb_range_beg_len (VALUE range, long *begp, long *lenp, long len, int err)
 
static VALUE range_to_s (VALUE range)
 
static VALUE inspect_range (VALUE range, VALUE dummy, int recur)
 
static VALUE range_inspect (VALUE range)
 
static VALUE range_eqq (VALUE range, VALUE val)
 
static VALUE range_include (VALUE range, VALUE val)
 
static VALUE range_cover (VALUE range, VALUE val)
 
static VALUE range_dumper (VALUE range)
 
static VALUE range_loader (VALUE range, VALUE obj)
 
static VALUE range_alloc (VALUE klass)
 
void Init_Range (void)
 

Variables

VALUE rb_cRange
 
static ID id_cmp
 
static ID id_succ
 
static ID id_beg
 
static ID id_end
 
static ID id_excl
 
static ID id_integer_p
 
static ID id_div
 
static VALUE
 
 else
 
return Qnil
 
long n = NUM2LONG(ary[0])
 
 ary [0] = INT2NUM(n)
 

Macro Definition Documentation

#define BSEARCH (   conv)
Value:
do { \
if (EXCL(range)) high--; \
org_high = high; \
while (low < high) { \
mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
: (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
BSEARCH_CHECK(conv(mid)); \
if (smaller) { \
high = mid; \
} \
else { \
low = mid + 1; \
} \
} \
if (low == org_high) { \
BSEARCH_CHECK(conv(low)); \
if (!smaller) return Qnil; \
} \
if (!satisfied) return Qnil; \
return conv(low); \
} while (0)
return
Definition: bigdecimal.c:5946
#define RETURN_ENUMERATOR(obj, argc, argv)
#define EXCL(r)
Definition: range.c:33
if(args--[1]==0)
Definition: array.c:3187
while(a->frac[0]/shift==0)
Definition: bigdecimal.c:5241
#define Qnil
Definition: enum.c:67
#define range(low, item, hi)
Definition: date_strftime.c:21
#define BSEARCH_CHECK(val)
else
Definition: enum.c:452

Referenced by range_bsearch().

#define BSEARCH_CHECK (   val)
Value:
do { \
if (FIXNUM_P(v)) { \
if (FIX2INT(v) == 0) return val; \
smaller = FIX2INT(v) < 0; \
} \
else if (v == Qtrue) { \
satisfied = 1; \
smaller = 1; \
} \
else if (v == Qfalse || v == Qnil) { \
smaller = 0; \
} \
if (!cmp) return val; \
smaller = cmp < 0; \
} \
else { \
rb_raise(rb_eTypeError, "wrong argument type %s" \
" (must be numeric, true, false or nil)", \
} \
} while (0)
VP_EXPORT int
Definition: bigdecimal.c:5172
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
return
Definition: bigdecimal.c:5946
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
rb_yield(i)
VALUE rb_eTypeError
Definition: error.c:548
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
return Qtrue
Definition: tcltklib.c:9618
if(args--[1]==0)
Definition: array.c:3187
int rb_cmpint(VALUE val, VALUE a, VALUE b)
Definition: bignum.c:2909
return Qfalse
Definition: tcltklib.c:6790
#define FIXNUM_P(f)
#define Qnil
Definition: enum.c:67
#define val
Definition: tcltklib.c:1935
#define FIX2INT(x)
#define INT2FIX(i)
static ID id_cmp
Definition: range.c:23
else
Definition: enum.c:452
VALUE v
Definition: enum.c:845
VALUE cmp
Definition: enum.c:1246
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:646
unsigned long VALUE
Definition: ripper.y:88
RUBY_EXTERN VALUE rb_cNumeric
Definition: ripper.y:1583

Referenced by range_bsearch().

#define EXCL (   r)    RTEST(RANGE_EXCL(r))
#define RANGE_BEG (   r)    (RSTRUCT(r)->as.ary[0])
#define RANGE_END (   r)    (RSTRUCT(r)->as.ary[1])
#define RANGE_EXCL (   r)    (RSTRUCT(r)->as.ary[2])

Definition at line 27 of file range.c.

Referenced by range_dumper(), and range_modify().

#define RANGE_SET_BEG (   r,
  v 
)    (RSTRUCT_SET(r, 0, v))

Definition at line 28 of file range.c.

Referenced by range_init(), and range_loader().

#define RANGE_SET_END (   r,
  v 
)    (RSTRUCT_SET(r, 1, v))

Definition at line 29 of file range.c.

Referenced by range_init(), and range_loader().

#define RANGE_SET_EXCL (   r,
  v 
)    (RSTRUCT_SET(r, 2, v))

Definition at line 30 of file range.c.

Referenced by range_init(), and range_loader().

#define rb_intern (   str)    rb_intern_const(str)
#define RBOOL (   v)    ((v) ? Qtrue : Qfalse)

Definition at line 31 of file range.c.

Referenced by range_initialize(), and rb_range_new().

Function Documentation

static int discrete_object_p ( VALUE  obj)
static

Definition at line 326 of file range.c.

References FALSE, id_succ, rb_cTime, rb_obj_is_kind_of(), and rb_respond_to().

Referenced by range_each(), and range_step().

if ( FIXNUM_P(iter[0])  )

Definition at line 294 of file range.c.

References FIXNUM_FLAG, and INT2FIX.

if ( iter  [0] = INT2FIX(0))

Definition at line 300 of file range.c.

References i, rb_str_intern(), and rb_yield().

if ( n<=  0)

Definition at line 855 of file range.c.

References rb_iter_break().

void Init_Range ( void  )
static VALUE inspect_range ( VALUE  range,
VALUE  dummy,
int  recur 
)
static

Definition at line 1087 of file range.c.

References EXCL, OBJ_INFECT, RANGE_BEG, RANGE_END, rb_inspect(), rb_str_append(), rb_str_cat(), rb_str_dup(), rb_str_new2, and str.

Referenced by range_inspect().

static int is_integer_p ( VALUE  v)
static

Definition at line 527 of file range.c.

References id_integer_p, Qundef, rb_check_funcall(), and RTEST.

Referenced by range_bsearch().

static int linear_object_p ( VALUE  obj)
static
static int r_le ( VALUE  a,
VALUE  b 
)
static

Definition at line 185 of file range.c.

References c, id_cmp, INT2FIX, NIL_P(), Qfalse, Qtrue, r, rb_cmpint(), and rb_funcall().

Referenced by range_cover(), range_each_func(), and range_include().

static int r_lt ( VALUE  a,
VALUE  b 
)
static

Definition at line 173 of file range.c.

References id_cmp, NIL_P(), Qfalse, Qtrue, r, rb_cmpint(), and rb_funcall().

Referenced by range_cover(), range_each_func(), and range_include().

static VALUE range_alloc ( VALUE  klass)
static

Definition at line 1271 of file range.c.

References rb_struct_alloc_noinit().

Referenced by Init_Range().

static VALUE range_begin ( VALUE  range)
static

Definition at line 825 of file range.c.

References RANGE_BEG.

Referenced by Init_Range().

static VALUE range_bsearch ( VALUE  range)
static
static VALUE range_check ( VALUE args)
static

Definition at line 43 of file range.c.

References id_cmp, and rb_funcall().

Referenced by range_init().

static VALUE range_cover ( VALUE  range,
VALUE  val 
)
static

Definition at line 1223 of file range.c.

References end, EXCL, Qfalse, Qtrue, r_le(), r_lt(), RANGE_BEG, and RANGE_END.

Referenced by Init_Range().

static VALUE range_dumper ( VALUE  range)
static
static VALUE range_each ( VALUE  range)
static
static void range_each_func ( VALUE  range,
rb_block_call_func func,
VALUE  arg 
)
static

Definition at line 266 of file range.c.

References arg, b, c, e, EXCL, id_succ, INT2FIX, Qfalse, r_le(), r_lt(), RANGE_BEG, RANGE_END, rb_funcall(), and v.

Referenced by range_each(), and range_step().

static VALUE range_end ( VALUE  range)
static

Definition at line 843 of file range.c.

References RANGE_END.

Referenced by Init_Range().

static VALUE range_enum_size ( VALUE  range,
VALUE  args,
VALUE  eobj 
)
static

Definition at line 741 of file range.c.

References range_size().

Referenced by range_each().

static VALUE range_eq ( VALUE  range,
VALUE  obj 
)
static

Definition at line 162 of file range.c.

References Qfalse, Qtrue, rb_cRange, rb_exec_recursive_paired(), rb_obj_is_kind_of(), and recursive_equal().

Referenced by Init_Range().

static VALUE range_eql ( VALUE  range,
VALUE  obj 
)
static

Definition at line 230 of file range.c.

References Qfalse, Qtrue, rb_cRange, rb_exec_recursive_paired(), rb_obj_is_kind_of(), and recursive_eql().

Referenced by Init_Range().

static VALUE range_eqq ( VALUE  range,
VALUE  val 
)
static

Definition at line 1140 of file range.c.

References rb_funcall(), and rb_intern.

Referenced by Init_Range().

static VALUE range_exclude_end_p ( VALUE  range)
static

Definition at line 127 of file range.c.

References EXCL, Qfalse, and Qtrue.

Referenced by Init_Range().

static VALUE range_failed ( void  )
static

Definition at line 36 of file range.c.

References Qnil, rb_eArgError, and rb_raise().

Referenced by range_init().

static VALUE range_first ( int  argc,
VALUE argv,
VALUE  range 
)
static

Definition at line 877 of file range.c.

References n, NUM2LONG, RANGE_BEG, rb_ary_new2, rb_block_call(), and rb_scan_args().

Referenced by Init_Range().

static VALUE range_hash ( VALUE  range)
static

Definition at line 249 of file range.c.

References EXCL, hash, LONG2FIX, NUM2LONG, RANGE_BEG, RANGE_END, rb_hash(), rb_hash_end, rb_hash_start(), rb_hash_uint, and v.

Referenced by Init_Range().

static VALUE range_include ( VALUE  range,
VALUE  val 
)
static
static void range_init ( VALUE  range,
VALUE  beg,
VALUE  end,
VALUE  exclude_end 
)
static
static VALUE range_initialize ( int  argc,
VALUE argv,
VALUE  range 
)
static

Definition at line 97 of file range.c.

References end, flags, Qnil, range_init(), range_modify(), rb_scan_args(), RBOOL, and RTEST.

Referenced by Init_Range().

static VALUE range_initialize_copy ( VALUE  range,
VALUE  orig 
)
static

Definition at line 109 of file range.c.

References range, range_modify(), and rb_struct_init_copy().

Referenced by Init_Range().

static VALUE range_inspect ( VALUE  range)
static

Definition at line 1115 of file range.c.

References inspect_range(), and rb_exec_recursive().

Referenced by Init_Range().

static VALUE range_last ( int  argc,
VALUE argv,
VALUE  range 
)
static

Definition at line 910 of file range.c.

References RANGE_END, rb_Array(), and rb_ary_last().

Referenced by Init_Range().

static VALUE range_loader ( VALUE  range,
VALUE  obj 
)
static
static VALUE range_max ( VALUE  range)
static
static VALUE range_min ( VALUE  range)
static

Definition at line 933 of file range.c.

References b, c, e, EXCL, id_cmp, Qnil, RANGE_BEG, RANGE_END, rb_block_given_p(), rb_call_super(), rb_cmpint(), and rb_funcall().

Referenced by Init_Range().

static void range_modify ( VALUE  range)
static

Definition at line 79 of file range.c.

References Qnil, RANGE_EXCL, and rb_name_error().

Referenced by range_initialize(), range_initialize_copy(), and range_loader().

static VALUE range_size ( VALUE  range)
static
static VALUE range_step ( int  argc,
VALUE argv,
VALUE  range 
)
static
static VALUE range_step_size ( VALUE  range,
VALUE  args,
VALUE  eobj 
)
static
static VALUE range_to_s ( VALUE  range)
static

Definition at line 1072 of file range.c.

References EXCL, OBJ_INFECT, RANGE_BEG, RANGE_END, rb_obj_as_string(), rb_str_append(), rb_str_cat(), rb_str_dup(), and str.

Referenced by Init_Range().

rb_ary_push ( ary  [1],
i   
)
VALUE rb_range_beg_len ( VALUE  range,
long *  begp,
long *  lenp,
long  len,
int  err 
)
VALUE rb_range_new ( VALUE  beg,
VALUE  end,
int  exclude_end 
)

Definition at line 70 of file range.c.

References range, range_init(), rb_cRange, rb_obj_alloc(), and RBOOL.

Referenced by fixup_nodes().

int rb_range_values ( VALUE  range,
VALUE begp,
VALUE endp,
int exclp 
)
static VALUE recursive_eql ( VALUE  range,
VALUE  obj,
int  recur 
)
static

Definition at line 202 of file range.c.

References EXCL, Qfalse, Qtrue, RANGE_BEG, RANGE_END, and rb_eql().

Referenced by range_eql().

static VALUE recursive_equal ( VALUE  range,
VALUE  obj,
int  recur 
)
static

Definition at line 133 of file range.c.

References EXCL, Qfalse, Qtrue, RANGE_BEG, RANGE_END, and rb_equal().

Referenced by range_eq().

Variable Documentation

ary[0] = INT2NUM(n)

Definition at line 860 of file range.c.

else
Initial value:
{
iter[0] = rb_funcall(iter[0], '-', 1, INT2FIX(1))
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
#define INT2FIX(i)

Definition at line 297 of file range.c.

ID id_beg
static

Definition at line 23 of file range.c.

Referenced by Init_Range(), range_dumper(), range_loader(), and rb_range_values().

ID id_cmp
static

Definition at line 23 of file range.c.

Referenced by Init_Range(), r_le(), r_lt(), range_bsearch(), range_check(), range_max(), and range_min().

ID id_div
static

Definition at line 23 of file range.c.

Referenced by Init_Range(), and range_bsearch().

ID id_end
static

Definition at line 23 of file range.c.

Referenced by Init_Range(), range_dumper(), range_loader(), and rb_range_values().

ID id_excl
static

Definition at line 23 of file range.c.

Referenced by Init_Range(), range_dumper(), and range_loader().

ID id_integer_p
static

Definition at line 23 of file range.c.

Referenced by Init_Range(), and is_integer_p().

ID id_succ
static

Definition at line 23 of file range.c.

Referenced by discrete_object_p(), Init_Range(), and range_each_func().

n = NUM2LONG(ary[0])

Definition at line 853 of file range.c.

return Qnil

Definition at line 304 of file range.c.

VALUE rb_cRange

Definition at line 22 of file range.c.

VALUE
static
Initial value:
{
VALUE *iter = (VALUE *)arg
VALUE arg
Definition: enum.c:2427
unsigned long VALUE
Definition: ripper.y:88

Definition at line 291 of file range.c.