Skip to content

Commit

Permalink
py/lexer: Convert mp_uint_t to size_t where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed Feb 17, 2017
1 parent d87c6b6 commit 5124a94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions py/lexer.c
Expand Up @@ -157,7 +157,7 @@ STATIC void next_char(mp_lexer_t *lex) {
}
}

STATIC void indent_push(mp_lexer_t *lex, mp_uint_t indent) {
STATIC void indent_push(mp_lexer_t *lex, size_t indent) {
if (lex->num_indent_level >= lex->alloc_indent_level) {
// TODO use m_renew_maybe and somehow indicate an error if it fails... probably by using MP_TOKEN_MEMORY_ERROR
lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC);
Expand All @@ -166,7 +166,7 @@ STATIC void indent_push(mp_lexer_t *lex, mp_uint_t indent) {
lex->indent_level[lex->num_indent_level++] = indent;
}

STATIC mp_uint_t indent_top(mp_lexer_t *lex) {
STATIC size_t indent_top(mp_lexer_t *lex) {
return lex->indent_level[lex->num_indent_level - 1];
}

Expand Down Expand Up @@ -263,7 +263,7 @@ STATIC const char *const tok_kw[] = {
// This is called with CUR_CHAR() before first hex digit, and should return with
// it pointing to last hex digit
// num_digits must be greater than zero
STATIC bool get_hex(mp_lexer_t *lex, mp_uint_t num_digits, mp_uint_t *result) {
STATIC bool get_hex(mp_lexer_t *lex, size_t num_digits, mp_uint_t *result) {
mp_uint_t num = 0;
while (num_digits-- != 0) {
next_char(lex);
Expand Down Expand Up @@ -354,7 +354,7 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw) {
default:
if (c >= '0' && c <= '7') {
// Octal sequence, 1-3 chars
mp_uint_t digits = 3;
size_t digits = 3;
mp_uint_t num = c - '0';
while (is_following_odigit(lex) && --digits != 0) {
next_char(lex);
Expand Down Expand Up @@ -458,7 +458,7 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
} else if (had_physical_newline && lex->nested_bracket_level == 0) {
lex->tok_kind = MP_TOKEN_NEWLINE;

mp_uint_t num_spaces = lex->column - 1;
size_t num_spaces = lex->column - 1;
if (num_spaces == indent_top(lex)) {
} else if (num_spaces > indent_top(lex)) {
indent_push(lex, num_spaces);
Expand Down Expand Up @@ -622,7 +622,7 @@ void mp_lexer_to_next(mp_lexer_t *lex) {
// search for encoded delimiter or operator

const char *t = tok_enc;
mp_uint_t tok_enc_index = 0;
size_t tok_enc_index = 0;
for (; *t != 0 && !is_char(lex, *t); t += 1) {
if (*t == 'e' || *t == 'c') {
t += 1;
Expand All @@ -644,7 +644,7 @@ void mp_lexer_to_next(mp_lexer_t *lex) {

// get the maximum characters for a valid token
t += 1;
mp_uint_t t_index = tok_enc_index;
size_t t_index = tok_enc_index;
for (;;) {
for (; *t == 'e'; t += 1) {
t += 1;
Expand Down Expand Up @@ -762,7 +762,7 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) {
return lex;
}

mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len) {
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, size_t len, size_t free_len) {
mp_reader_t reader;
if (!mp_reader_new_mem(&reader, (const byte*)str, len, free_len)) {
return NULL;
Expand Down
14 changes: 7 additions & 7 deletions py/lexer.h
Expand Up @@ -151,24 +151,24 @@ typedef struct _mp_lexer_t {

unichar chr0, chr1, chr2; // current cached characters from source

mp_uint_t line; // current source line
mp_uint_t column; // current source column
size_t line; // current source line
size_t column; // current source column

mp_int_t emit_dent; // non-zero when there are INDENT/DEDENT tokens to emit
mp_int_t nested_bracket_level; // >0 when there are nested brackets over multiple lines

mp_uint_t alloc_indent_level;
mp_uint_t num_indent_level;
size_t alloc_indent_level;
size_t num_indent_level;
uint16_t *indent_level;

mp_uint_t tok_line; // token source line
mp_uint_t tok_column; // token source column
size_t tok_line; // token source line
size_t tok_column; // token source column
mp_token_kind_t tok_kind; // token kind
vstr_t vstr; // token data
} mp_lexer_t;

mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader);
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len);
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, size_t len, size_t free_len);

void mp_lexer_free(mp_lexer_t *lex);
void mp_lexer_to_next(mp_lexer_t *lex);
Expand Down

0 comments on commit 5124a94

Please sign in to comment.