[pypy-commit] creflect default: structs and unions
arigo
noreply at buildbot.pypy.org
Sat Nov 29 11:18:48 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r114:5948e2d049a7
Date: 2014-11-29 11:19 +0100
http://bitbucket.org/cffi/creflect/changeset/5948e2d049a7/
Log: structs and unions
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
@@ -406,6 +406,8 @@
case TOK__BOOL:
case TOK_FLOAT:
case TOK_IDENTIFIER:
+ case TOK_STRUCT:
+ case TOK_UNION:
return parse_error(tok, "invalid combination of types");
case TOK_DOUBLE:
@@ -468,6 +470,25 @@
t1 = tok->cb->get_user_type(tok->cb, identifier);
break;
}
+ case TOK_STRUCT:
+ case TOK_UNION:
+ {
+ char identifier[1024];
+ crx_type_t *(*get_type)(crx_builder_t *, const char *);
+ if (tok->kind == TOK_STRUCT)
+ get_type = tok->cb->get_struct_type;
+ else
+ get_type = tok->cb->get_union_type;
+ next_token(tok);
+ if (tok->kind != TOK_IDENTIFIER)
+ return parse_error(tok, "struct or union name expected");
+ if (tok->size >= 1024)
+ return parse_error(tok, "struct or union name too long");
+ memcpy(identifier, tok->p, tok->size);
+ identifier[tok->size] = 0;
+ t1 = get_type(tok->cb, identifier);
+ break;
+ }
default:
return parse_error(tok, "identifier expected");
}
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
@@ -85,6 +85,8 @@
parse("float", "float")
parse("double", "double")
parse("long double", "long double")
+ parse("struct foo_s", "STRUCT foo_s")
+ parse("union foo_u *", "PTR UNION foo_u")
def test_c_decl_error():
parse_error("short short int", "'short' after another 'short' or 'long'", 6)
@@ -107,6 +109,8 @@
parse_error("int(]", "identifier expected", 4)
parse_error("int[?]", "expected an integer constant", 4)
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" + "[]" * 2500, "type too lengthy", 3337)
parse_error("f" * 1200, "identifier name too long", 0)
More information about the pypy-commit
mailing list