[pypy-commit] creflect default: The two special rules for function argument types

arigo noreply at buildbot.pypy.org
Sat Nov 29 10:09:15 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r111:9eb51bd08098
Date: 2014-11-29 10:09 +0100
http://bitbucket.org/cffi/creflect/changeset/9eb51bd08098/

Log:	The two special rules for function argument 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
@@ -165,7 +165,7 @@
     return result;
 }
 
-static crx_type_t *parse_complete(crxp_token_t *tok);
+static crx_type_t *parse_complete(crxp_token_t *tok, int is_func_arg);
 
 static void parse_sequel(crxp_token_t *tok, intptr_t ds_end)
 {
@@ -207,7 +207,7 @@
                         next_token(tok);
                         break;
                     }
-                    crx_type_t *t1 = parse_complete(tok);
+                    crx_type_t *t1 = parse_complete(tok, 1);
                     intptr_t *ds_type = alloc_ds(tok, 1);
                     assert(ds_type == ds + 2 + ds[1]);
                     *ds_type = (intptr_t)t1;
@@ -256,7 +256,7 @@
 }
 
 static crx_type_t *fetch_delay_slots(crxp_token_t *tok, crx_type_t *t1,
-                                     intptr_t *delay_slot)
+                                     intptr_t *delay_slot, int is_func_arg)
 {
     tok->delay_slots = delay_slot;
     while (1) {
@@ -274,6 +274,11 @@
             case TOK_OPEN_BRACKET:   /* array */
             {
                 uintptr_t length = (uintptr_t)*delay_slot++;
+                if (is_func_arg && *delay_slot == TOK_END) {
+                    /* function argument: replace an array with a ptr */
+                    t1 = tok->cb->get_pointer_type(tok->cb, t1);
+                    break;
+                }
                 if (length != (uintptr_t)-1)
                     t1 = tok->cb->get_array_type(tok->cb, t1, length);
                 else
@@ -281,21 +286,21 @@
                 break;
             }
             case TOK_OPEN_PAREN:   /* function */
+            case TOK_DOTDOTDOT:    /* function ending with a '...' */
             {
                 intptr_t nbargs = *delay_slot++;
                 crx_type_t **argtypes = (crx_type_t **)delay_slot;
                 delay_slot += nbargs;
-                t1 = tok->cb->get_function_type(tok->cb, t1, argtypes,
-                                                nbargs, NULL);
-                break;
-            }
-            case TOK_DOTDOTDOT:   /* function ending with a '...' */
-            {
-                intptr_t nbargs = *delay_slot++;
-                crx_type_t **argtypes = (crx_type_t **)delay_slot;
-                delay_slot += nbargs;
-                t1 = tok->cb->get_ellipsis_function_type(tok->cb, t1,
-                                                         argtypes, nbargs);
+                if (tok_kind == TOK_DOTDOTDOT)
+                    t1 = tok->cb->get_ellipsis_function_type(tok->cb, t1,
+                                                             argtypes, nbargs);
+                else
+                    t1 = tok->cb->get_function_type(tok->cb, t1, argtypes,
+                                                    nbargs, NULL);
+                if (is_func_arg && *delay_slot == TOK_END) {
+                    /* function argument: replace a func with a ptr-to-func */
+                    t1 = tok->cb->get_pointer_type(tok->cb, t1);
+                }
                 break;
             }
             default:
@@ -314,7 +319,7 @@
     return NULL;
 }
 
-static crx_type_t *parse_complete(crxp_token_t *tok)
+static crx_type_t *parse_complete(crxp_token_t *tok, int is_func_arg)
 {
     crx_type_t *t1;
     int is_const = (tok->kind == TOK_CONST);
@@ -423,7 +428,7 @@
 
     intptr_t *orig = tok->delay_slots;
     parse_sequel(tok, TOK_END);
-    return fetch_delay_slots(tok, t1, orig);
+    return fetch_delay_slots(tok, t1, orig, is_func_arg);
 }
 
 const char *creflect_decl_parser(crx_builder_t *cb, const char *input,
@@ -436,7 +441,7 @@
     token.size = 0;
     token.delay_slots = token.all_delay_slots;
     next_token(&token);
-    *result = parse_complete(&token);
+    *result = parse_complete(&token, 0);
 
     if (token.kind == TOK_END)
         return NULL;
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
@@ -78,9 +78,8 @@
     parse("foo_t", "foo_t")
     parse("foo_t*", "PTR foo_t")
     parse("int(int, ...)", "FUNC( int -> ... -> int )")
-    import py; py.test.skip("in-progress")
-    parse("int(int[])")
-    parse("int(long(char))")
+    parse("int(int[])", "FUNC( PTR int -> int )")
+    parse("int(long(char))", "FUNC( PTR FUNC( char -> long ) -> int )")
 
 def test_c_decl_error():
     parse_error("*", 0)


More information about the pypy-commit mailing list