[pypy-commit] creflect default: The remaining primitive types
arigo
noreply at buildbot.pypy.org
Sat Nov 29 11:18:47 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r113:deab50fe7ed9
Date: 2014-11-29 11:15 +0100
http://bitbucket.org/cffi/creflect/changeset/deab50fe7ed9/
Log: The remaining primitive types
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
@@ -402,29 +402,41 @@
switch (tok->kind) {
+ case TOK_VOID:
+ case TOK__BOOL:
+ case TOK_FLOAT:
+ case TOK_IDENTIFIER:
+ return parse_error(tok, "invalid combination of types");
+
+ case TOK_DOUBLE:
+ if (modifiers_sign != 0 || modifiers_length != 1)
+ return parse_error(tok, "invalid combination of types");
+ next_token(tok);
+ t1 = tok->cb->get_float_type(tok->cb, sizeof(long double),
+ "long double");
+ break;
+
case TOK_CHAR:
if (modifiers_length != 0)
- return parse_error(tok,"cannot combine with 'short' or 'long'");
- size = sizeof(char);
- name = "char";
- next_token(tok);
- break;
-
+ return parse_error(tok, "invalid combination of types");
+ modifiers_length = -2;
+ /* fall-through */
case TOK_INT:
next_token(tok);
/* fall-through */
default:
switch (modifiers_length) {
- case -1: size = sizeof(short); name = "short"; break;
- case 1: size = sizeof(long); name = "long"; break;
+ case -2: size = sizeof(char); name = "char"; break;
+ case -1: size = sizeof(short); name = "short"; break;
+ case 1: size = sizeof(long); name = "long"; break;
case 2: size = sizeof(long long); name = "long long"; break;
- default: size = sizeof(int); name = "int"; break;
+ default: size = sizeof(int); name = "int"; break;
}
+ if (modifiers_sign < 0)
+ t1 = tok->cb->get_unsigned_type(tok->cb, size, name);
+ else
+ t1 = tok->cb->get_signed_type(tok->cb, size, name);
}
- if (modifiers_sign < 0)
- t1 = tok->cb->get_unsigned_type(tok->cb, size, name);
- else
- t1 = tok->cb->get_signed_type(tok->cb, size, name);
}
else {
switch (tok->kind) {
@@ -437,6 +449,15 @@
case TOK_VOID:
t1 = tok->cb->get_void_type(tok->cb);
break;
+ case TOK__BOOL:
+ t1 = tok->cb->get_bool_type(tok->cb);
+ break;
+ case TOK_FLOAT:
+ t1 = tok->cb->get_float_type(tok->cb, sizeof(float), "float");
+ break;
+ case TOK_DOUBLE:
+ t1 = tok->cb->get_float_type(tok->cb, sizeof(double), "double");
+ break;
case TOK_IDENTIFIER:
{
char identifier[1024];
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
@@ -81,6 +81,10 @@
parse("int(int, ...)", "FUNC( int -> ... -> int )")
parse("int(int[])", "FUNC( PTR int -> int )")
parse("int(long(char))", "FUNC( PTR FUNC( char -> long ) -> int )")
+ parse("_Bool", "_Bool")
+ parse("float", "float")
+ parse("double", "double")
+ parse("long double", "long double")
def test_c_decl_error():
parse_error("short short int", "'short' after another 'short' or 'long'", 6)
@@ -88,13 +92,16 @@
parse_error("short long", "'long' after 'short'", 6)
parse_error("signed unsigned int", "multiple 'signed' or 'unsigned'", 7)
parse_error("unsigned signed int", "multiple 'signed' or 'unsigned'", 9)
- parse_error("long char", "cannot combine with 'short' or 'long'", 5)
- parse_error("short char", "cannot combine with 'short' or 'long'", 6)
+ parse_error("long char", "invalid combination of types", 5)
+ parse_error("short char", "invalid combination of types", 6)
+ parse_error("signed void", "invalid combination of types", 7)
+ parse_error("unsigned foobar_t", "invalid combination of types", 9)
#
parse_error("", "identifier expected", 0)
parse_error("]", "identifier expected", 0)
parse_error("*", "identifier expected", 0)
parse_error("int ]**", "unexpected symbol", 4)
+ parse_error("char char", "unexpected symbol", 5)
parse_error("int(int]", "expected ')'", 7)
parse_error("int(*]", "expected ')'", 5)
parse_error("int(]", "identifier expected", 4)
More information about the pypy-commit
mailing list