Author: Armin Rigo <[email protected]>
Branch:
Changeset: r116:61c8089f6f6b
Date: 2014-11-29 12:08 +0100
http://bitbucket.org/cffi/creflect/changeset/61c8089f6f6b/
Log: More corner cases
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
@@ -69,14 +69,14 @@
return (is_ident_first(x) || is_digit(x));
}
-static int is_following_token_this_char(crxp_token_t *tok, char expected)
+static char get_following_char(crxp_token_t *tok)
{
const char *p = tok->p + tok->size;
if (tok->kind == TOK_ERROR)
return 0;
while (is_space(*p))
p++;
- return *p == expected;
+ return *p;
}
static void next_token(crxp_token_t *tok)
@@ -188,20 +188,28 @@
next_token(tok);
}
+ int check_for_grouping = -1;
+ if (tok->kind == TOK_IDENTIFIER) {
+ next_token(tok); /* skip a potential variable name */
+ check_for_grouping = 1;
+ }
+
intptr_t *jump_slot = alloc_ds(tok, 1);
if (jump_slot == NULL)
return;
*jump_slot = ds_end;
next_right_part:
+ check_for_grouping++;
+
switch (tok->kind) {
case TOK_OPEN_PAREN:
next_token(tok);
- if (tok->kind == TOK_STAR ||
- tok->kind == TOK_CONST ||
- tok->kind == TOK_OPEN_BRACKET) {
+ if (check_for_grouping == 0 && (tok->kind == TOK_STAR ||
+ tok->kind == TOK_CONST ||
+ tok->kind == TOK_OPEN_BRACKET)) {
/* just parentheses for grouping */
ds = tok->delay_slots;
parse_sequel(tok, *jump_slot);
@@ -214,8 +222,7 @@
return;
ds[0] = TOK_OPEN_PAREN;
ds[1] = 0;
- if (tok->kind == TOK_VOID &&
- is_following_token_this_char(tok, ')')) {
+ if (tok->kind == TOK_VOID && get_following_char(tok) == ')') {
next_token(tok);
}
if (tok->kind != TOK_CLOSE_PAREN) {
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
@@ -87,6 +87,10 @@
parse("long double", "long double")
parse("struct foo_s", "STRUCT foo_s")
parse("union foo_u *", "PTR UNION foo_u")
+ parse("void *", "PTR void")
+ parse("int a", "int")
+ parse("int *abc", "PTR int")
+ parse("int myfunc(int a[])", "FUNC( PTR int -> int )")
def test_c_decl_error():
parse_error("short short int", "'short' after another 'short' or 'long'",
6)
@@ -111,6 +115,8 @@
parse_error("int[24)", "expected ']'", 6)
parse_error("struct", "struct or union name expected", 6)
parse_error("struct 24", "struct or union name expected", 7)
+ parse_error("int[5](*)", "identifier expected", 7)
+ parse_error("int a(*)", "identifier expected", 6)
#
parse_error("int" + "[]" * 2500, "type too lengthy", 3337)
parse_error("f" * 1200, "identifier name too long", 0)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit