summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authortake_cheeze <[email protected]>2013-09-02 22:12:55 +0900
committertake_cheeze <[email protected]>2013-09-02 22:12:55 +0900
commit8588c5445230c52ee638becbccd8cee148332657 (patch)
treec5bf6cde735f9c4c7cfe2df65b33b6123db34daa /src
parentaddb57f7e572db3cf9e2f68295f20321291501c6 (diff)
downloadmruby-8588c5445230c52ee638becbccd8cee148332657.tar.gz
mruby-8588c5445230c52ee638becbccd8cee148332657.zip
declare variable outside for
Diffstat (limited to 'src')
-rw-r--r--src/debug.c12
-rw-r--r--src/dump.c37
-rw-r--r--src/load.c22
-rw-r--r--src/parse.y3
4 files changed, 47 insertions, 27 deletions
diff --git a/src/debug.c b/src/debug.c
index 28691ca1b..3b8d52f3d 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -37,7 +37,8 @@ select_line_type(uint16_t const* lines, size_t lines_len)
{
size_t line_count = 0;
int prev_line = -1;
- for (size_t i = 0; i < lines_len; ++i) {
+ size_t i;
+ for (i = 0; i < lines_len; ++i) {
if (lines[i] != prev_line) {
++line_count;
}
@@ -153,7 +154,8 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
case mrb_debug_line_ary:
ret->line_entry_count = file_pc_count;
ret->line_ary = mrb_malloc(mrb, sizeof(uint16_t) * file_pc_count);
- for(uint32_t i = 0; i < file_pc_count; ++i) {
+ uint32_t i;
+ for(i = 0; i < file_pc_count; ++i) {
ret->line_ary[i] = irep->lines[start_pos + i];
}
break;
@@ -162,7 +164,8 @@ mrb_debug_info_append_file(mrb_state* mrb, mrb_irep* irep,
ret->line_flat_map = mrb_malloc(mrb, sizeof(mrb_irep_debug_info_line) * 1);
ret->line_entry_count = 0;
uint16_t prev_line = 0;
- for(uint32_t i = 0; i < file_pc_count; ++i) {
+ uint32_t i;
+ for(i = 0; i < file_pc_count; ++i) {
if(irep->lines[start_pos + i] == prev_line) { continue; }
ret->line_flat_map = mrb_realloc(
@@ -188,7 +191,8 @@ mrb_debug_info_free(mrb_state* mrb, mrb_irep_debug_info* d)
{
if(!d) { return; }
- for(uint32_t i = 0; i < d->flen; ++i) {
+ uint32_t i;
+ for(i = 0; i < d->flen; ++i) {
mrb_assert(d->files[i]);
mrb_free(mrb, d->files[i]->line_ptr);
mrb_free(mrb, d->files[i]);
diff --git a/src/dump.c b/src/dump.c
index 92b1b011a..2f6be4c72 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -398,7 +398,8 @@ get_debug_record_size(mrb_state* mrb, mrb_irep *irep) {
ret += sizeof(uint32_t); // record size
ret += sizeof(uint16_t); // file count
- for(uint32_t f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
+ uint32_t f_idx;
+ for(f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
mrb_irep_debug_info_file const* file = irep->debug_info->files[f_idx];
ret += sizeof(uint32_t); // position
@@ -425,7 +426,8 @@ get_debug_record_size(mrb_state* mrb, mrb_irep *irep) {
static int
find_filename_index(mrb_value const ary, mrb_sym s) {
- for(mrb_int i = 0; i < RARRAY_LEN(ary); ++i) {
+ mrb_int i;
+ for(i = 0; i < RARRAY_LEN(ary); ++i) {
mrb_assert(mrb_symbol_p(RARRAY_PTR(ary)[i]));
if(mrb_symbol(RARRAY_PTR(ary)[i]) == s) { return i; }
}
@@ -438,7 +440,8 @@ write_debug_record(mrb_state* mrb, mrb_irep *irep, uint8_t * const bin, mrb_valu
uint8_t *cur = bin + sizeof(uint32_t); // skip record size
cur += uint16_to_bin(irep->debug_info->flen, cur); // file count
- for(uint32_t f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
+ uint32_t f_idx;
+ for(f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
mrb_irep_debug_info_file const* file = irep->debug_info->files[f_idx];
// position
@@ -454,17 +457,19 @@ write_debug_record(mrb_state* mrb, mrb_irep *irep, uint8_t * const bin, mrb_valu
cur += uint8_to_bin(file->line_type, cur);
switch(file->line_type) {
case mrb_debug_line_ary: {
- for(size_t l = 0; l < file->line_entry_count; ++l) {
+ size_t l;
+ for(l = 0; l < file->line_entry_count; ++l) {
cur += uint16_to_bin(file->line_ary[l], cur);
}
} break;
- case mrb_debug_line_flat_map:
- for(uint32_t line = 0; line < file->line_entry_count; ++line) {
+ case mrb_debug_line_flat_map: {
+ uint32_t line;
+ for(line = 0; line < file->line_entry_count; ++line) {
cur += uint32_to_bin(file->line_flat_map[line].start_pos, cur);
cur += uint16_to_bin(file->line_flat_map[line].line, cur);
}
- break;
+ } break;
default: mrb_assert(0); break;
}
@@ -497,10 +502,12 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
uint8_t* const filenames_len = cur;
cur += sizeof(uint16_t);
section_size += sizeof(uint16_t);
- for (size_t irep_i = start_index; irep_i < mrb->irep_len; ++irep_i) {
+ size_t irep_i;
+ for (irep_i = start_index; irep_i < mrb->irep_len; ++irep_i) {
mrb_irep_debug_info const* debug_info = mrb->irep[irep_i]->debug_info;
- for(size_t file_i = 0; file_i < debug_info->flen; ++file_i) {
+ size_t file_i;
+ for(file_i = 0; file_i < debug_info->flen; ++file_i) {
mrb_irep_debug_info_file const* file = debug_info->files[file_i];
if(find_filename_index(filenames, file->filename_sym) != -1) continue;
@@ -519,7 +526,8 @@ mrb_write_section_debug(mrb_state* mrb, size_t start_index, uint8_t *cur)
uint16_to_bin(RARRAY_LEN(filenames), filenames_len);
// records
- for (size_t i = start_index; i < mrb->irep_len; ++i) {
+ size_t i;
+ for (i = start_index; i < mrb->irep_len; ++i) {
uint32_t rlen = write_debug_record(mrb, mrb->irep[i], cur, filenames);
cur += rlen;
section_size += rlen;
@@ -554,7 +562,8 @@ write_rite_binary_header(mrb_state *mrb, size_t binary_size, uint8_t* bin)
}
mrb_bool is_debug_info_defined(mrb_state* mrb, size_t const start_index) {
- for (size_t i = start_index; i < mrb->irep_len; ++i) {
+ size_t i;
+ for (i = start_index; i < mrb->irep_len; ++i) {
if (!mrb->irep[i]->debug_info) { return 0; }
}
return 1;
@@ -592,10 +601,12 @@ mrb_dump_irep(mrb_state *mrb, size_t start_index, int debug_info, uint8_t **bin,
mrb_value const filenames = mrb_ary_new(mrb);
// filename table size
section_lineno_size += sizeof(uint16_t);
- for (size_t irep_i = start_index; irep_i < mrb->irep_len; ++irep_i) {
+ size_t irep_i;
+ for (irep_i = start_index; irep_i < mrb->irep_len; ++irep_i) {
mrb_irep_debug_info const* di = mrb->irep[irep_i]->debug_info;
- for(size_t file_i = 0; file_i < di->flen; ++file_i) {
+ size_t file_i;
+ for(file_i = 0; file_i < di->flen; ++file_i) {
mrb_irep_debug_info_file const* file = di->files[file_i];
if(find_filename_index(filenames, file->filename_sym) != -1) continue;
diff --git a/src/load.c b/src/load.c
index 3bdf39e73..64e592a9e 100644
--- a/src/load.c
+++ b/src/load.c
@@ -317,7 +317,8 @@ static int read_rite_debug_record(mrb_state* mrb, uint8_t const *start, size_t i
irep->debug_info->files = (mrb_irep_debug_info_file**)mrb_malloc(mrb, sizeof(mrb_irep_debug_info*) * irep->debug_info->flen);
bin += sizeof(uint16_t);
- for (uint16_t f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
+ uint16_t f_idx;
+ for (f_idx = 0; f_idx < irep->debug_info->flen; ++f_idx) {
mrb_irep_debug_info_file* const file = (mrb_irep_debug_info_file*)mrb_malloc(mrb, sizeof(mrb_irep_debug_info_file));
irep->debug_info->files[f_idx] = file;
@@ -332,20 +333,22 @@ static int read_rite_debug_record(mrb_state* mrb, uint8_t const *start, size_t i
file->line_entry_count = bin_to_uint32(bin); bin += sizeof(uint32_t);
file->line_type = bin_to_uint8(bin); bin += sizeof(uint8_t);
switch(file->line_type) {
- case mrb_debug_line_ary:
+ case mrb_debug_line_ary: {
file->line_ary = mrb_malloc(mrb, sizeof(uint16_t) * file->line_entry_count);
- for(size_t l = 0; l < file->line_entry_count; ++l) {
+ size_t l;
+ for(l = 0; l < file->line_entry_count; ++l) {
file->line_ary[l] = bin_to_uint16(bin); bin += sizeof(uint16_t);
}
- break;
+ } break;
- case mrb_debug_line_flat_map:
+ case mrb_debug_line_flat_map: {
file->line_flat_map = mrb_malloc(mrb, sizeof(mrb_irep_debug_info_line) * file->line_entry_count);
- for(size_t l = 0; l < file->line_entry_count; ++l) {
+ size_t l;
+ for(l = 0; l < file->line_entry_count; ++l) {
file->line_flat_map[l].start_pos = bin_to_uint32(bin); bin += sizeof(uint32_t);
file->line_flat_map[l].line = bin_to_uint16(bin); bin += sizeof(uint16_t);
}
- break;
+ } break;
default: return MRB_DUMP_GENERAL_FAILURE;
}
@@ -366,20 +369,21 @@ read_rite_section_debug(mrb_state* mrb, const uint8_t* start, size_t sirep)
uint8_t const* bin = start;
struct rite_section_debug_header const* header = (struct rite_section_debug_header const*)bin;
bin += sizeof(struct rite_section_debug_header);
+ uint16_t i;
uint16_t const nirep = bin_to_uint16(header->nirep);
uint16_t const filenames_len = bin_to_uint16(bin);
mrb_value const filenames = mrb_ary_new_capa(mrb, filenames_len);
bin += sizeof(uint16_t);
- for(uint16_t i = 0; i < filenames_len; ++i) {
+ for(i = 0; i < filenames_len; ++i) {
uint16_t const f_len = bin_to_uint16(bin);
bin += sizeof(uint16_t);
mrb_ary_push(mrb, filenames, mrb_symbol_value(mrb_intern2(mrb, (char const*)bin, f_len)));
bin += f_len;
}
- for(uint16_t i = sirep; i < (sirep + nirep); ++i) {
+ for(i = sirep; i < (sirep + nirep); ++i) {
uint32_t len = 0;
int result = read_rite_debug_record(mrb, bin, i, &len, filenames);
if (result != MRB_DUMP_OK) { return result; }
diff --git a/src/parse.y b/src/parse.y
index 8bbfea668..bcc5fd35e 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -5188,7 +5188,8 @@ mrb_parser_set_filename(struct mrb_parser_state* p, char const* f)
p->filename = mrb_sym2name_len(p->mrb, sym, &len);
p->lineno = 1;
- for(size_t i = 0; i < p->filename_table_length; ++i) {
+ size_t i;
+ for(i = 0; i < p->filename_table_length; ++i) {
if(p->filename_table[i] == sym) {
p->current_filename_index = i;
return;