Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r104:388bb851de61 Date: 2014-11-28 23:18 +0100 http://bitbucket.org/cffi/creflect/changeset/388bb851de61/
Log: simple arrays diff --git a/creflect/src/c_decl_parser.c b/creflect/src/c_decl_parser.c --- a/creflect/src/c_decl_parser.c +++ b/creflect/src/c_decl_parser.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <assert.h> #include "creflect.h" @@ -52,9 +53,14 @@ return ('A' <= x && x <= 'Z' || 'a' <= x && x <= 'z' || x == '_'); } +static int is_digit(char x) +{ + return ('0' <= x && x <= '9'); +} + static int is_ident_next(char x) { - return (is_ident_first(x) || '0' <= x && x <= '9'); + return (is_ident_first(x) || is_digit(x)); } static void next_token(crxp_token_t *tok) @@ -66,6 +72,14 @@ if (is_space(*p)) { p++; } + else if (is_digit(*p)) { + tok->kind = TOK_INTEGER; + tok->p = p; + tok->size = 1; + while (is_digit(p[tok->size])) + tok->size++; + return; + } else if (*p) { tok->kind = *p; tok->p = p; @@ -79,11 +93,11 @@ return; } } + tok->kind = TOK_IDENTIFIER; tok->p = p; tok->size = 1; while (is_ident_next(p[tok->size])) tok->size++; - tok->kind = TOK_IDENTIFIER; switch (*p) { case '_': @@ -128,11 +142,20 @@ abort(); case TOK_OPEN_BRACKET: - abort(); + next_token(tok); + assert(tok->kind == TOK_INTEGER); // XXX + unsigned long long length = strtoull(tok->p, NULL, 10); + next_token(tok); + assert(tok->kind == TOK_CLOSE_BRACKET); // XXX + next_token(tok); + t1 = parse_sequel_right(tok, t1); + t1 = tok->cb->get_array_type(tok->cb, t1, (size_t)length); + break; default: - return t1; + break; } + return t1; } static crx_type_t *parse_sequel(crxp_token_t *tok, crx_type_t *t1) diff --git a/test/test_c_decl_parser.py b/test/test_c_decl_parser.py --- a/test/test_c_decl_parser.py +++ b/test/test_c_decl_parser.py @@ -50,9 +50,9 @@ parse("int const **", "PTR PTR CONST int") parse("int *const *", "PTR CONST PTR int") parse("int ** const", "CONST PTR PTR int") + parse("int[2]", "ARRAY[2] int") + parse("int*[2][3]", "ARRAY[2] ARRAY[3] PTR int") import py; py.test.skip("in-progress") - parse("int[2]") - parse("int*[2][3]") parse("int(*)[2][3]") parse("int(*[2])[3]") parse("int()") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit