Skip to content

Commit

Permalink
Fixing compile error...
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Apr 5, 2024
1 parent cd8439d commit 575e6fe
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions ext/rbs_extension/location.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define RBS_LOC_REQUIRED_P(loc, i) ((loc)->children->required_p & (1 << (i)))
#define RBS_LOC_OPTIONAL_P(loc, i) (!RBS_LOC_REQUIRED_P((loc), (i)))

rbs_loc_range RBS_LOC_NULL_RANGE = { -1, -1 };
VALUE RBS_Location;

position rbs_loc_position(int char_pos) {
Expand All @@ -15,6 +16,11 @@ position rbs_loc_position3(int char_pos, int line, int column) {
return pos;
}

rbs_loc_range rbs_new_loc_range(range rg) {
rbs_loc_range r = { rg.start.char_pos, rg.end.char_pos };
return r;
}

static void check_children_max(unsigned short n) {
size_t max = sizeof(rbs_loc_entry_bitmap) * 8;
if (n > max) {
Expand Down Expand Up @@ -50,7 +56,7 @@ void rbs_loc_add_required_child(rbs_loc *loc, ID name, range r) {

unsigned short i = loc->children->len++;
loc->children->entries[i].name = name;
loc->children->entries[i].rg = r;
loc->children->entries[i].rg = rbs_new_loc_range(r);

loc->children->required_p |= 1 << i;
}
Expand All @@ -60,10 +66,10 @@ void rbs_loc_add_optional_child(rbs_loc *loc, ID name, range r) {

unsigned short i = loc->children->len++;
loc->children->entries[i].name = name;
loc->children->entries[i].rg = r;
loc->children->entries[i].rg = rbs_new_loc_range(r);
}

void rbs_loc_init(rbs_loc *loc, VALUE buffer, range rg) {
void rbs_loc_init(rbs_loc *loc, VALUE buffer, rbs_loc_range rg) {
loc->buffer = buffer;
loc->rg = rg;
loc->children = NULL;
Expand Down Expand Up @@ -99,7 +105,7 @@ static VALUE location_s_allocate(VALUE klass) {
rbs_loc *loc;
VALUE obj = TypedData_Make_Struct(klass, rbs_loc, &location_type, loc);

rbs_loc_init(loc, Qnil, NULL_RANGE);
rbs_loc_init(loc, Qnil, RBS_LOC_NULL_RANGE);

return obj;
}
Expand All @@ -111,8 +117,8 @@ rbs_loc *rbs_check_location(VALUE obj) {
static VALUE location_initialize(VALUE self, VALUE buffer, VALUE start_pos, VALUE end_pos) {
rbs_loc *loc = rbs_check_location(self);

position start = rbs_loc_position(FIX2INT(start_pos));
position end = rbs_loc_position(FIX2INT(end_pos));
int start = FIX2INT(start_pos);
int end = FIX2INT(end_pos);

loc->buffer = buffer;
loc->rg.start = start;
Expand All @@ -139,38 +145,21 @@ static VALUE location_buffer(VALUE self) {

static VALUE location_start_pos(VALUE self) {
rbs_loc *loc = rbs_check_location(self);
return INT2FIX(loc->rg.start.char_pos);
return INT2FIX(loc->rg.start);
}

static VALUE location_end_pos(VALUE self) {
rbs_loc *loc = rbs_check_location(self);
return INT2FIX(loc->rg.end.char_pos);
return INT2FIX(loc->rg.end);
}

// TODO: remove it
static VALUE location_start_loc(VALUE self) {
rbs_loc *loc = rbs_check_location(self);

if (loc->rg.start.line >= 0) {
VALUE pair = rb_ary_new_capa(2);
rb_ary_push(pair, INT2FIX(loc->rg.start.line));
rb_ary_push(pair, INT2FIX(loc->rg.start.column));
return pair;
} else {
return Qnil;
}
return Qnil;
}

static VALUE location_end_loc(VALUE self) {
rbs_loc *loc = rbs_check_location(self);

if (loc->rg.end.line >= 0) {
VALUE pair = rb_ary_new_capa(2);
rb_ary_push(pair, INT2FIX(loc->rg.end.line));
rb_ary_push(pair, INT2FIX(loc->rg.end.column));
return pair;
} else {
return Qnil;
}
return Qnil;
}

static VALUE location_add_required_child(VALUE self, VALUE name, VALUE start, VALUE end) {
Expand Down Expand Up @@ -209,7 +198,7 @@ VALUE rbs_new_location(VALUE buffer, range rg) {
rbs_loc *loc;
VALUE obj = TypedData_Make_Struct(RBS_Location, rbs_loc, &location_type, loc);

rbs_loc_init(loc, buffer, rg);
rbs_loc_init(loc, buffer, rbs_new_loc_range(rg));

return obj;
}
Expand Down

0 comments on commit 575e6fe

Please sign in to comment.